note 101482 deleted from function.is-callable by danbrown
| From: | danbrown@php.net | Date: | Sun, 19 Dec 2010 19:15:01 +0000 |
| Subject: | note 101482 deleted from function.is-callable by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-175069@lists.php.net to get a copy of this message | ||
Note Submitter: devis at lucato dot it
----
Regarding the previous comment on closures, in case you need it they can be made
"callable" with a simple workaround
class TestClass
{
public $testMethod;
public function __construct()
{
$this->testMethod = function(){};
}
function __call($name, $arguments)
{
// Note: Closure class is an implementation detail
// so it might be removed or renamed in the future
if (isset($this->$name) && $this->$name instanceof Closure)
{
return call_user_func_array($this->$name, $arguments);
}
}
}
$test = new TestClass();
var_dump(is_callable(array($test, 'testMethod'))); // false
var_dump(is_callable($test->testMethod)); // true
--
see http://lucato.it/php-anonymous-objects for
use cases