note 96168 added to function.is-callable
| From: | Mathias at donotspamnooku dot org | Date: | Thu, 11 Feb 2010 23:45:38 +0000 |
| Subject: | note 96168 added to function.is-callable | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-165893@lists.php.net to get a copy of this message | ||
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')
);
----
Server IP: 217.71.118.166
Probable Submitter: 81.241.89.15
----
Manual Page -- http://www.php.net/manual/en/function.is-callable.php
Edit -- https://master.php.net/note/edit/96168
Del: integrated -- https://master.php.net/note/delete/96168/integrated
Del: useless -- https://master.php.net/note/delete/96168/useless
Del: bad code -- https://master.php.net/note/delete/96168/bad+code
Del: spam -- https://master.php.net/note/delete/96168/spam
Del: non-english -- https://master.php.net/note/delete/96168/non-english
Del: in docs -- https://master.php.net/note/delete/96168/in+docs
Del: other reasons-- https://master.php.net/note/delete/96168
Reject -- https://master.php.net/note/reject/96168
Search -- https://master.php.net/manage/user-notes.php