3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Ex extends \ReflectionException { public $reflector; public function __construct($reflector, $message = '', \Exception $previous = null) { parent::__construct($message, 0, $previous); $this->reflector = $reflector; } } class A { private $private = 'private'; public $public = 'public'; private function privateMethod() { } } class B { private $private = 'private'; public $public = 'public'; } class C extends \ReflectionClass { public function __construct($name) { try { parent::__construct($name); } catch (\Exception $e) { throw new Ex($this, $e->getMessage(), $e); } } } $r = new \ReflectionClass('A'); $p = $r->getProperty('private'); $p->setAccessible(true); //$p->setAccessible(false); $c = new B(); $p->setValue($c, 'b'); var_dump($p->getValue($c)); //$p = $r->getProperty('public'); //$p->setAccessible(false); //var_dump($p->getValue(true));
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught Error: Cannot access private property B::$private in /in/eOts8:50 Stack trace: #0 /in/eOts8(50): ReflectionProperty->setValue(Object(B), 'b') #1 {main} thrown in /in/eOts8 on line 50
Process exited with code 255.

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:
48.02 ms | 401 KiB | 8 Q