3v4l.org

run code in 300+ PHP versions simultaneously
<?php class PrivacyViolator { public function callPrivateMethod($object, $method, array $args = array()) { if (!is_object($object)) { throw new \InvalidArgumentException('The $object param must be object'); } $className = get_class($object); $method = new \ReflectionMethod($className, $method); $method->setAccessible(true); return $method->invokeArgs($object, $args); } } class MyClass { private function hello($name) { return 'Hello ' . $name; } } $myObject = new MyClass(); $privacyViolator = new PrivacyViolator(); $result = $privacyViolator->callPrivateMethod($myObject, 'hello', array('World')); echo $result; assert('Hello World' === $result);
Output for git.master, git.master_jit, rfc.property-hooks
Hello World

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
40.29 ms | 401 KiB | 8 Q