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

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -