@ 2016-11-09T00:53:06Z <?php
class my_private_class {
private function my_private_method() {
echo 'execute me!';
}
}
class another_class {
public function execute_private_methods($instance) {
$instance->my_private_method();
}
}
$object = new my_private_class();
$reflection = new \ReflectionClass('my_private_class');
$method = $reflection->getMethod('my_private_method');
$method->setAccessible(true);
$method->invokeArgs($object);
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.7 Fatal error: Uncaught ArgumentCountError: ReflectionMethod::invokeArgs() expects exactly 2 arguments, 1 given in /in/ZjYjG:19
Stack trace:
#0 /in/ZjYjG(19): ReflectionMethod->invokeArgs(Object(my_private_class))
#1 {main}
thrown in /in/ZjYjG on line 19
Process exited with code 255 . Output for 5.6.0 - 5.6.40 , 7.0.0 - 7.0.33 , 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 Warning: ReflectionMethod::invokeArgs() expects exactly 2 parameters, 1 given in /in/ZjYjG on line 19
preferences:dark mode live preview
197.06 ms | 403 KiB | 292 Q