3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class A { private $private = 'private'; public $public = 'public'; } class B { //public $private = 'pr'; private $public = 'pu'; } $r = new \ReflectionClass('A'); $p = $r->getProperty('private'); $p->setAccessible(true); $p->setAccessible(false); var_dump($p->getValue(new B())); $p = $r->getProperty('public'); $p->setAccessible(false); var_dump($p->getValue(new A()));
Output for 7.0.0 - 7.1.0
Fatal error: Uncaught ReflectionException: Cannot access non-public member A::private in /in/tsbXH:19 Stack trace: #0 /in/tsbXH(19): ReflectionProperty->getValue(Object(B)) #1 {main} thrown in /in/tsbXH on line 19
Process exited with code 255.
Output for hhvm-3.10.0 - 3.12.0
NULL string(6) "public"
Output for 5.3.0 - 5.6.28
Fatal error: Uncaught exception 'ReflectionException' with message 'Cannot access non-public member A::private' in /in/tsbXH:19 Stack trace: #0 /in/tsbXH(19): ReflectionProperty->getValue(Object(B)) #1 {main} thrown in /in/tsbXH on line 19
Process exited with code 255.
Output for 5.0.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/tsbXH on line 15 Fatal error: Call to undefined method ReflectionProperty::setAccessible() in /in/tsbXH on line 17
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/tsbXH on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/tsbXH on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/tsbXH on line 5
Process exited with code 255.