zend_call_method() not invoking subclass method
| From: | Nathan Nobbe | Date: | Thu, 08 Jan 2009 04:12:59 +0000 |
| Subject: | zend_call_method() not invoking subclass method | ||
| Groups: | php.pecl.dev | ||
| Request: | Send a blank email to pecl-dev+get-6044@lists.php.net to get a copy of this message | ||
hello again,
ive moved on in my extension and am now perplexed by a new issue.
i have declared a class MacroCommand, which has a protected method
initializeMacroCommand. the MacroCommand constructor invokes
$this->initializeMacroCommand(), which works IFF i instantiate MacroCommand
directly. However, if i subclass it and overrride initializeMacroCommand in
the child class, the MacroCommand constructor does not invoke the
initializeMacroCommand method of the child, rather it invokes the
initializeMacroCommand method of the base class, MacroCommand.
as a simple test, i put an echo statement in the overriden
initializeMacroCommand definition, in the child class,
class MyMacroCommand extends MacroCommand {
protected function initializeMacroCommand() {
echo 'holy crap' . PHP_EOL; # <-- expect to see this when
MacroCommand::__construct runs
$this->addSubCommand(new SubCommand());
}
}
then, i put an E_NOTICE in the MacroCommand::initializeMacroCommand at the C
level,
/* MacroCommand */
/* {{{ proto protected void MacroCommand::initializeMacroCommand
this is a hook method to be overriden by subclasses, which will be called
by the constructor */
PHP_METHOD(MacroCommand, initializeMacroCommand)
{
php_error_docref(NULL TSRMLS_CC, E_NOTICE,
"initializeMacroCommand", NULL);
}
and when i run the test, its clear the wrong method is being called,
Notice: MacroCommand::initializeMacroCommand(): initializeMacroCommand in
/Users/nnobbe/phpdownloads/php5.2/ext/pure_mvc/tests/testMacroCommandAddSubCommand.php
on line 12
thoughts?
-nathan