note 118623 added to function.is-callable
| From: | izharaazmi at gmail dot com | Date: | Mon, 11 Jan 2016 06:50:21 +0000 |
| Subject: | note 118623 added to function.is-callable | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204637@lists.php.net to get a copy of this message | ||
If the target class has __call() magic function implemented, then is_callable will ALWAYS return
TRUE for whatever method you call it.
is_callable does not evaluate your internal logic inside __call() implementation (and this is for
good).
Therefore every method name is callable for such classes.
Hence it is WRONG to say (as someone said):
...is_callable will correctly determine the existence of methods made with __call...
Example:
<?php
class TestCallable
{
public function testing()
{
return "I am called.";
}
public function __call($name, $args)
{
if($name == 'testingOther')
{
return call_user_func_array(array($this, 'testing'), $args);
}
}
}
$t = new TestCallable();
echo $t->testing(); // Output: I am called.
echo $t->testingOther(); // Output: I am called.
echo $t->working(); // Output: (null)
echo is_callable(array($t, 'testing')); // Output: TRUE
echo is_callable(array($t, 'testingOther')); // Output: TRUE
echo is_callable(array($t, 'working')); // Output: TRUE, expected: FALSE
?>
----
Server IP: 72.52.91.14
Probable Submitter: 117.247.230.96
----
Manual Page -- http://php.net/manual/en/function.is-callable.php
Edit -- https://master.php.net/note/edit/118623
Del: integrated -- https://master.php.net/note/delete/118623/integrated
Del: useless -- https://master.php.net/note/delete/118623/useless
Del: bad code -- https://master.php.net/note/delete/118623/bad+code
Del: spam -- https://master.php.net/note/delete/118623/spam
Del: non-english -- https://master.php.net/note/delete/118623/non-english
Del: in docs -- https://master.php.net/note/delete/118623/in+docs
Del: other reasons-- https://master.php.net/note/delete/118623
Reject -- https://master.php.net/note/reject/118623
Search -- https://master.php.net/manage/user-notes.php