php - Anonymous function for a method of an object -
possible duplicate:
calling closure assigned object property directly
why not possible in php? want able create function on fly particular object.
$a = 'a'; $tokenmapper->tokenjoinhistories = function($a) { echo $a; }; $tokenmapper->tokenjoinhistories($a);
with $obj->foo()
call methods, want call property as function/method. confuses parser, because didn't find method name foo()
, cannot expect property callable.
call_user_func($tokenmapper->tokenjoinhistories, $a);
or extend mapper like
class bar { public function __call ($name, $args) { if (isset($this->$name) && is_callable($this->$name)) { return call_user_func_array($this->$name, $args); } else { throw new exception("undefined method '$name'"); } } }
(there issues within written example)
Comments
Post a Comment