Re: on the subject of overloading: __call()

From: Date: Mon, 18 Nov 2002 01:27:14 +0000
Subject: Re: on the subject of overloading: __call()
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-91204@lists.php.net to get a copy of this message
On Sun, 17 Nov 2002, Stanislav Malyshev wrote: > BB>> related topic: in the current state of ze2, there are several ways to > BB>> call methods directly that can't be emulated by call_user_func() - > BB>> calling self::method() for instance, or the visibility of $this if > BB>> you call class::method(). is that likely to stay true? > > Since __call is the method of the class, calling self::method can be > achieved, I think. As for the second point - could you please explain > furher what you mean, maybe with an example? right, because static method calls don't get caught by __call, so you always have $this. the basic problem is that as it is now, if i do any of these self::a_method($arg1,$arg2); parent::a_method($arg1,$arg2); some_other_class::a_method($arg1,$arg2); inside of a class's method, $this is visible inside those called methods, and points to the calling object. but there is no way to make equivalent calls using call_user_func() or call_user_func_array(). you can't use "parent::a_method", array($this,'parent::a_method'), array(parent,"a_method"), or array('parent',"a_method"). if you use the literal class name, call_user_func_array(array(get_parent_class($this),'a_method'), $args); it doesn't fail, but it's as if you were making a static method call from outside of an object context - $this is not defined. it's the last two cases - parent:: and some_other_class:: - that relate to __call(), as you point out. and what truly matters is call_user_func_array(), because not having it means you can't hand off the arguments from __call()'s parameters to a method in the parent class or in some other class. not without writing some pretty hacky eval() code, that is. (btw, there should probably be a warning in the docs that methods that are expecting to force their parameters to be references will not work as expected when called by call_user_func_array().) i'm attaching kind of long test case code & resulting output that show what i mean.

« previous php.dev (#91204) next »