For PHP 5.6 and higher
PHP 5.6 introduces variable arguments that can also take parameters by reference.
function makePublicAndCall ($objectInstance, $methodname, &...$args) { }
now just move the array $argsfilled with arguments with a link$objectInstance->$methodname
function makePublicAndCall ($objectInstance, $methodname, &...$args) {
$ref = new ReflectionMethod (get_class($objectInstance), $methodname);
$ref->setAccessible(true);
return $ref->invokeArgs($objectInstance, $args);
}
makePublicAndCall($object, 'testMe', $output);
PHP 5.4 5.5
, , .
PHP 5.3
, .
function makePublicAndCall ($objectInstance, $methodname) {
$ref = new ReflectionMethod (get_class($objectInstance), $methodname);
$ref->setAccessible(true);
return $ref->invokeArgs ($objectInstance, $args);
}
@makePublicAndCall($object, 'testMe', &$output);
, testMe, , , ; , ref, .