note 103889 added to function.call-user-func
| From: | romainbessuges at gmail dot com | Date: | Mon, 09 May 2011 12:50:11 +0000 |
| Subject: | note 103889 added to function.call-user-func | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-179559@lists.php.net to get a copy of this message | ||
I made a wrapper for call_user_func_array which is really simple and convenient. It takes advantage
of the __invoke() magic method :
class Func {
public static function fromFunction($name){
return new Func($name);
}
public static function fromClassMethod($class, $name){
return new Func(array($class, $name));
}
public static function fromObjectMethod($object, $name){
return new Func(array($object, $name));
}
public $function;
public function __construct($function) {
$this->function = $function;
}
public function __invoke(){
return call_user_func_array($this->function, func_get_args());
}
}
Example :
$func = Func::fromObjectMethod($myArrayObject, "offsetGet");
echo $func(3);
----
Server IP: 69.147.83.197
Probable Submitter: 88.180.244.120
----
Manual Page -- http://www.php.net/manual/en/function.call-user-func.php
Edit -- https://master.php.net/note/edit/103889
Del: integrated -- https://master.php.net/note/delete/103889/integrated
Del: useless -- https://master.php.net/note/delete/103889/useless
Del: bad code -- https://master.php.net/note/delete/103889/bad+code
Del: spam -- https://master.php.net/note/delete/103889/spam
Del: non-english -- https://master.php.net/note/delete/103889/non-english
Del: in docs -- https://master.php.net/note/delete/103889/in+docs
Del: other reasons-- https://master.php.net/note/delete/103889
Reject -- https://master.php.net/note/reject/103889
Search -- https://master.php.net/manage/user-notes.php