Re: __call overload detection

From: Date: Tue, 03 Jan 2006 21:50:24 +0000
Subject: Re: __call overload detection
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-21376@lists.php.net to get a copy of this message
Hello Andrew, you do not implement __call for a method but you deal with the method name in any sense you like, which also includes ignoring specific __call invocations. Reflection gives you the ability to check whetehr a function is being physically available. If you need more it is up to you to provide the infrastructure. Remember we will not in anyway allow __call to handle inheritance. regards marcus Tuesday, January 3, 2006, 10:33:32 PM, you wrote: > Hi Marcus, > On Tue, Jan 03, 2006 at 10:06:56PM +0100, Marcus Boerger wrote: >> Hello Andrew, >> >> right now you can use reflection. >> >> marcus > The reflection APIs do not help I believe. Consider that one may only > want __call to respond to a computable set of overloaded method names. > Right now, is_callable returns true for any requested method if __call > is implemented by the object. Unless I have missed some magic that the > Reflection APIs can do, they don't apply here. > Consider the following: > class a { > var $callables = array('foo'); > function __call($name, $args) { > if ($this->__is_callable($name)) return 'good call'; > else return 'bad call'; > } > function __is_callable($name) { > return in_array($name, $this->callables); > } > } > $a = new a(); > print "is_callable: " . is_callable(array($a,'foo'),false, $callable) . > " as $callable \n"; > // prints: is_callable: 1 as a::foo > // OK > print "is_callable: " . is_callable(array($a,'bar'),false, $callable) . > " as $callable \n"; > // result: is_callable: 1 as a::bar > // desired: is_callable: 0 as > // or some other similar behavior if __is_callable is implemented > If one were to implement a reflection-like method called __iscallable, > you could get this functionality, but couldn't count on other's code > using the same convention. Another downside to doing it yourself is > that every call to a method must first check __is_callable - this could > be handled by the language upon a method call. If I feel it would be a > good idea to implement this in the lanaguage for standardization and > simplicity. > Regards, > Andrew Best regards, Marcus

« previous php.internals (#21376) next »