3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class MyClass { public $public = 'Pub'; protected $protected = 'Protec'; private $private = 'Pri'; function printHello() { echo $this->public; echo $this->protected; echo $this->private; } } class MyClass2 extends MyClass { // We can redeclare the public and protected method, but not private protected $protected = 'Protected2'; function printHello() { echo $this->public; echo $this->protected; echo $this->private; } } $obj2 = new MyClass2(); //echo $obj2->public; // Works //echo $obj2->protected; // Fatal Error //echo $obj2->private; // Undefined $obj2->printHello(); // Shows Public, Protected2, Undefined ?>
Output for 5.2.6 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
PubProtected2 Notice: Undefined property: MyClass2::$private in /in/Q0OAV on line 27
Output for 5.0.0 - 5.2.5
PubProtected2 Notice: Undefined property: MyClass2::$private in /in/Q0OAV on line 27
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/Q0OAV on line 6
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/Q0OAV on line 6
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/Q0OAV on line 6
Process exited with code 255.