Re: note 98221 deleted from function.call-user-func-array by degeberg
| From: | Daniel Egeberg | Date: | Wed, 02 Jun 2010 15:32:20 +0000 |
| Subject: | Re: note 98221 deleted from function.call-user-func-array by degeberg | ||
| References: | 1 2 3 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-169824@lists.php.net to get a copy of this message | ||
On Wed, Jun 2, 2010 at 17:20, Daniel P. Brown <daniel.brown@parasane.net> wrote:
> What was the reason for removing this note, Dan?
Hmm... well, when I read it I just immediately thought "duh, of
course". I guess if it isn't obvious that you can do that, it would be
better adding another example to the manual than having it as a user
note.
> 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!
>
> --
> PHP Notes Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Daniel Egeberg