|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-11-22 06:31 UTC] pierre at pcservice dot co dot za
Description:
------------
When you have a class that have a __call magic method, when calling is_callable
with an array and the first argument a string, it returns false.
Test script:
---------------
Class Foo {
public function __call($method, $args) {}
}
var_dump(is_callable(array('Foo', 'bar')));
var_dump(is_callable(array(new Foo, 'bar')));
Expected result:
----------------
true
true
Actual result:
--------------
false
true
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 15:00:01 2025 UTC |
so when calling is_callable(array('Foo', 'bar')), if the method doesn't exist, it only looks for a static method? with the following class Controller { public function testAction() { } public static function staticAction() { } public function __call($method, $arguments) { } } is_callable(array(new Controller, 'testAction')); is_callable(array(new Controller, 'staticAction')); is_callable(array(new Controller, 'fooAction')); is_callable(array('Controller', 'testAction')); is_callable(array('Controller', 'staticAction')); is_callable(array('Controller', 'fooAction')); everything returns true except for the last call. Shouldn't it return true as well, since the class has the magic __call method? Or the documentation should then at least specify that is_callable only works with the __call method, if the first parameter of the array is an instance of the objectis_callable(array(new Controller, 'fooAction')); // call of a regular method _call() works fine. is_callable(array('Controller', 'fooAction')); // attempt to call a static method __call() doesn't try to call static methods, so is_callable() returns false.