note 96168 deleted from function.is-callable by danbrown

From: Date: Fri, 12 Feb 2010 02:44:06 +0000
Subject: note 96168 deleted from function.is-callable by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-165896@lists.php.net to get a copy of this message
Note Submitter: Mathias at donotspamnooku dot org ---- hcblue wrote: "is_callable() will be able to correctly recognize method calls handled by __call() in PHP 5" This is not true. When a class has a __call() method, is_callable returns true no matter what, even if, when actually executed, __call() would return false. Try this code: <?php class Foo { public function __call($method, $args) { if($method == 'a') return true; if($method == 'b') return false; } } class Bar{} $foo = new Foo; $bar = new Bar; var_dump( // these return true: is_callable(array($foo, 'a')), is_callable(array($foo, 'b')), // these return false: method_exists($foo, 'a'), method_exists($foo, 'b'), is_callable(array($bar, 'a')), method_exists($bar, 'a') );

« previous php.notes (#165896) next »