3v4l.org

run code in 300+ PHP versions simultaneously
<?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 git.master, git.master_jit, rfc.property-hooks
3

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