Re: __call overload detection

From: Date: Tue, 03 Jan 2006 21:33:32 +0000
Subject: Re: __call overload detection
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-21375@lists.php.net to get a copy of this message
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 -- Andrew Yochum Plexpod andrew@plexpod.com 718-360-0879

« previous php.internals (#21375) next »