note 100782 deleted from function.call-user-func-array by cmb
| From: | cmb@php.net | Date: | Sun, 30 Aug 2015 18:00:37 +0000 |
| Subject: | note 100782 deleted from function.call-user-func-array by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-203509@lists.php.net to get a copy of this message | ||
Note Submitter: orestes at orestescarracedo dot com
----
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);
?>