3v4l.org

run code in 300+ PHP versions simultaneously
<?php class PrivacyViolator { private $caller; function __construct() { $this->caller = function ($method, $args) { return call_user_func_array([$this, $method], $args); }; } function callPrivateMethod($object, $method, $args) { var_dump($method); $this->caller->bindTo($object, $object); return $this->caller($method, $args); } } class MyClass { private $private_var; private function hello() { return "I'm private method"; } } $myObject = new MyClass(); $privacyViolator = new PrivacyViolator(); $privacyViolator->callPrivateMethod($myObject, 'hello', ['world']);

preferences:
36.41 ms | 405 KiB | 6 Q