From what i've observed, call_user_func() does everything this funciton does and a little more. I made a pretty good example call_user_func()'s usage with object instances and figured it might be useful here:
<?php
class Runner {
public $id;
public function __construct($id) {
$this->id = $id;
echo "constructing " . __CLASS__ . " with id of $id<br />\n";
}
public function run($distance = null, $measurement = 'km') {
if ($distance) {
echo 'I ran ' . $distance . ' ' . $measurement . '.';
} else {
echo 'I ran.';
}
echo "({$this->id})<br />\n";
}
}
class Speaker {
public $id;
public function __construct($id = 0) {
$this->id = $id;
echo "constructing " . __CLASS__ . " with id of $id<br />\n";
}
public function speak($statement = 'hello world') {
echo $statement . "({$this->id})<br />\n";
}
}
class Test {
protected $runCallback = null;
protected $speakCallback = null;
protected $statement;
protected $distance;
public function __construct(array $params = array()) {
echo "constructing " . __CLASS__ . "<br />\n";
$params += array('speakCallback' => array('Speaker', 'speak'), 'runCallback' => array('Runner', 'run'), 'statement' => 'Hello from ' . __CLASS__ . ' class!', 'distance' => 10);
foreach($params as $k => $v) {
$this->$k = $v;
}
}
public function getInstance() {
return new self(current(func_get_args()));
}
public function callRunner() {
if (is_callable($this->runCallback))
return call_user_func($this->runCallback, $this->distance);
else
throw new Exception("runCallback is not callable\n" . var_export($this->runCallback, true) . "\n");
}
public function callSpeaker() {
if (is_callable($this->speakCallback))
return call_user_func($this->speakCallback, $this->statement);
else
throw new Exception("speakCallback is not callable\n" . var_export($this->speakCallback, true) . "\n");
}
}
$r = new Runner(1);
$s = new Speaker(2);
call_user_func(array($s, 'speak'), 'Hello from global!');
call_user_func_array(array($r, 'run'), array(5, 'mi'));
$Test = new Test(array('runCallback' => array($r, 'run'), 'speakCallback' => array($s, 'speak')));
$Test->callRunner();
$Test->callSpeaker();
$Test = call_user_func(array('Test', 'getInstance'), array('runCallback' => array($r, 'run'), 'distance' => 15));
$Test->callRunner();
$Test->callSpeaker();
?>
Hope that's helpful.