Re: zend_call_method() not invoking subclass method
| From: | Nathan Nobbe | Date: | Fri, 30 Jan 2009 04:14:44 +0000 |
| Subject: | Re: zend_call_method() not invoking subclass method | ||
| References: | 1 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-6095@lists.php.net to get a copy of this message | ||
On Wed, Jan 7, 2009 at 9:12 PM, Nathan Nobbe <quickshiftin@gmail.com> wrote:
> 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?
well, i figured it out! i was using the class definition of MacroCommand
statically, by placing puremvc_macrocommand_ce in the call to
zend_call_method_with_0_params. changing to zend_get_class_entry(this)
seems to be grabbing the class definition of the child at runtime and blamo,
the code is hitting the overriden subclass method!
-nathan