3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class User{ const GIVEN = 1; // class constants can't be labeled static nor assigned visibility public $a=2; public static $b=3; public function me(){ echo "print me"; } public static function you() { echo "print you"; } } class myUser extends User { } // Are properties and methods instantiated to an object of a class, & are they accessible? $object1= new User(); // uncomment this line with each of the following lines individually //echo $object1->GIVEN . ""; // yields nothing //echo $object1->GIVE . ""; // deliberately misnamed, still yields nothing //echo $object1->User::GIVEN . ""; // yields nothing //echo $object1->a . ""; // yields 2 //echo $object1->b . ""; // yields nothing //echo $object1->me() . ""; // yields print me //echo $object1->you() . ""; // yields print you // Are properties and methods instantiated to an object of a child class, & are accessible? //$object2= new myUser(); // uncomment this line with each of the following lines individually //echo $object2->GIVEN . ""; // yields nothing //echo $object2->a . ""; // yields 2 //echo $object2->b . ""; // yields nothing //echo $object2->me() . ""; // yields print me //echo $object2->you() . ""; // yields print you // Are the properties and methods accessible directly in the class? //echo User::GIVEN . ""; // yields 1 //echo User::$a . ""; // yields fatal error since it is not static //echo User::$b . ""; // yields 3 //echo User::me() . ""; // yields print me //echo User::you() . ""; // yields print you // Are the properties and methods copied to the child class and are they accessible? //echo myUser::GIVEN . ""; // yields 1 //echo myUser::$a . ""; // yields fatal error since it is not static echo myUser::$b . ""; // yields 3 //echo myUser::me() . ""; // yields print me //echo myUser::you() . ""; // yields print you
Output for 5.0.0 - 5.0.5, 5.1.1 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
3
Output for 5.1.0
Fatal error: fatal flex scanner internal error--end of buffer missed in /in/ceTeD on line 48
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/ceTeD on line 3
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_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/ceTeD on line 3
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/ceTeD on line 3
Process exited with code 255.