note 88394 deleted from language.oop5.static by cmb

From: Date: Sun, 01 Sep 2019 07:34:09 +0000
Subject: note 88394 deleted from language.oop5.static by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-212059@lists.php.net to get a copy of this message
Note Submitter: yesmarklapointe at hotmail dot com ---- <?php // experiments with static // tested on PHP 5.2.6 on 1-21-09 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 . "</br>"; // yields nothing //echo $object1->GIVE . "</br>"; // deliberately misnamed, still yields nothing //echo $object1->User::GIVEN . "</br>"; // yields nothing //echo $object1->a . "</br>"; // yields 2 //echo $object1->b . "</br>"; // yields nothing //echo $object1->me() . "</br>"; // yields print me //echo $object1->you() . "</br>"; // 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 . "</br>"; // yields nothing //echo $object2->a . "</br>"; // yields 2 //echo $object2->b . "</br>"; // yields nothing //echo $object2->me() . "</br>"; // yields print me //echo $object2->you() . "</br>"; // yields print you // Are the properties and methods accessible directly in the class? //echo User::GIVEN . "</br>"; // yields 1 //echo User::$a . "</br>"; // yields fatal error since it is not static //echo User::$b . "</br>"; // yields 3 //echo User::me() . "</br>"; // yields print me //echo User::you() . "</br>"; // yields print you // Are the properties and methods copied to the child class and are they accessible? //echo myUser::GIVEN . "</br>"; // yields 1 //echo myUser::$a . "</br>"; // yields fatal error since it is not static //echo myUser::$b . "</br>"; // yields 3 //echo myUser::me() . "</br>"; // yields print me //echo myUser::you() . "</br>"; // yields print you ?>

« previous php.notes (#212059) next »