3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Test { public $publicProperty; protected $protectedProperty; private $privateProperty; public function __construct() { unset( $this->publicProperty, $this->protectedProperty, $this->privateProperty ); } function __get($name) { echo 'called __get ' . $name; } function __set($name, $value) { echo 'called __set ' . $name . ' ' . $value; } } $t = new Test(); foreach (array('publicProperty', 'protectedProperty', 'privateProperty') as $propertyName) { $prop = new ReflectionProperty('Test', $propertyName); $prop->setAccessible(true); echo var_export($prop->getValue($t), true) . "\n"; $prop->setValue($t, 'value'); } ?>
Output for 5.3.0 - 5.6.25, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
called __get publicPropertyNULL called __set publicProperty valuecalled __get protectedPropertyNULL called __set protectedProperty valuecalled __get privatePropertyNULL called __set privateProperty value
Output for 5.0.0 - 5.2.17
Fatal error: Call to undefined method ReflectionProperty::setAccessible() in /in/OJCFg on line 30
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/OJCFg 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/OJCFg 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/OJCFg on line 5
Process exited with code 255.