Re: note 98221 deleted from function.call-user-func-array by degeberg

From: Date: Wed, 02 Jun 2010 15:20:06 +0000
Subject: Re: note 98221 deleted from function.call-user-func-array by degeberg
References: 1 2  Groups: php.notes 
Request: Send a blank email to php-notes+get-169823@lists.php.net to get a copy of this message
What was the reason for removing this note, Dan? On Wed, Jun 2, 2010 at 11:40, <degeberg@php.net> wrote: > Note Submitter: jimbo2150 (at) gmail (dot) com > > ---- > > I found an easy way to call a parent method in PHP < 5.3 without entering the method name > directly: > > <?php > class MyClass extends AnotherClass { >    function _myOverrideMethod() { >        call_user_func(array('parent',__FUNCTION__)); >    } > } > ?> > > This will call the parent method of the current class (AnotherClass::_myOverrideMethod). > > I also tried replacing __FUNCTION__ with __METHOD__ but that DOES NOT WORK. I var_dump'ed > __METHOD__ and realied it included the class name. So, for example, calling var_dump(__METHOD__) > within the class above will output 'MyClass::_myOverrideMethod' which will not work when > used as a replacement for __FUNCTION__ above because the call_user_func then tries to call > 'parent::MyClass::_myOverrideMethod' which DOES NOT WORK. __FUNCTION__ included only the > method name (without the class). To compare: here are the outputs side-by-side: > > <?php > // Supposing they were called within the MyClass::_myOverrideMethod method above... > var_dump(__METHOD__); // MyClass::_myOverrideMethod > var_dump(__FUNCTION__); // _myOverrideMethod > ?> > > -- > PHP Notes Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- </Daniel P. Brown> daniel.brown@parasane.net || danbrown@php.net http://www.parasane.net/ || http://www.pilotpig.net/ We now offer SAME-DAY SETUP on a new line of servers!

« previous php.notes (#169823) next »