note 100782 added to function.call-user-func-array
| From: | orestes at orestescarracedo dot com | Date: | Fri, 05 Nov 2010 21:24:04 +0000 |
| Subject: | note 100782 added to function.call-user-func-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-173805@lists.php.net to get a copy of this message | ||
It's not commented above:
This function behaves as call_user_func. To call a method of a class instace, instead of passing the
function name as the first argument, pass an array like ($classInstance, 'methodName)
<?php
public class Person {
private $name = null;
private $pocketContents= null;
protected function __construct() {
$this->name = 'My creator was too lazy to name me';
}
public function getName() {
return $this->name;
}
public function setName($name) {
$this->name = $name;
}
public function getPocketContents() {
return $this->$pocketContents;
}
public function setPocketContents() {
$args = func_get_args();
$this->$pocketContents = $args;
}
}
$contents = array();
$contents[0] = 'random';
$contents['foo'] = 'bar';
$subobject = array();
$subobject['param'] = 'value';
$contents['subobject'] = $subobject;
call_user_func(($myInstance, 'setPocketContents'), $contents);
?>
----
Server IP: 80.64.47.13
Probable Submitter: 81.184.6.13
----
Manual Page -- http://www.php.net/manual/en/function.call-user-func-array.php
Edit -- https://master.php.net/note/edit/100782
Del: integrated -- https://master.php.net/note/delete/100782/integrated
Del: useless -- https://master.php.net/note/delete/100782/useless
Del: bad code -- https://master.php.net/note/delete/100782/bad+code
Del: spam -- https://master.php.net/note/delete/100782/spam
Del: non-english -- https://master.php.net/note/delete/100782/non-english
Del: in docs -- https://master.php.net/note/delete/100782/in+docs
Del: other reasons-- https://master.php.net/note/delete/100782
Reject -- https://master.php.net/note/reject/100782
Search -- https://master.php.net/manage/user-notes.php