I don't care what its for, what I meant is what each of the class or objects are supposed to do.
What I'm saying is you cannot do this:
public static function dotest(&$var)
$var .= ', ' . $var;
$var = 'test';
call_user_func(array('Test', 'dotest'), $var);
As that will trigger a reference warning. call_user_func[_array] cannot be used to pass-by-reference parameters.
What needs to happen is either a common interface is implemented to every provided object so that it can force an invocation, or you can use reflection to generate this as well:
public static function dostatictest(&$var)
$var = $var . ', ' . $var;
public function dotest(&$var)
$this->var = $var .= ', ' . $var;
$var = 'static ok';
$rm1 = new ReflectionMethod('Test', 'dostatictest');
print $var . PHP_EOL;
$var = 'dynamic ok';
$obj = new Test();
$rm2 = new ReflectionMethod('Test', 'dotest');
print 'var: ' . $var . PHP_EOL;
print 'member: ' . $obj->var . PHP_EOL;
invokeArgs must be used; invoke will trigger a deprecation notice against the call-time pass-by-reference. I don't know if this is an oversight on the zend team, or if its a feature that will continue allowing us call-time pass-by-reference against the reflection's invoke.
Also note that this will work:
$var = 'call';
call_user_func_array(array('Test', 'dostatictest'), array(&$var));
print 'call: ' . $var . PHP_EOL;
without triggering a notice, but it is explicitly stated by the api to be deprecated (and makes note of the failure to trigger a notice): http://php.ca/manual/en/function.cal...nc-array-notes
. This is the reason why I cannot be sure that the invokeArgs is working as intended, even though there is no reference to an untriggered deprecation notice. This is why I would personally take an interface approach so I can be guaranteed of specific methods availability on an object. I don't believe this would work with static calls though, but I have never tried that.