note 88394 added to language.oop5.static

From: Date: Thu, 22 Jan 2009 07:19:06 +0000
Subject: note 88394 added to language.oop5.static
Groups: php.notes 
Request: Send a blank email to php-notes+get-149645@lists.php.net to get a copy of this message
<?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 ?> ---- Server IP: 69.147.83.197 Probable Submitter: 72.223.19.167 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.static.php Edit -- https://master.php.net/note/edit/88394 Del: integrated -- https://master.php.net/note/delete/88394/integrated Del: useless -- https://master.php.net/note/delete/88394/useless Del: bad code -- https://master.php.net/note/delete/88394/bad+code Del: spam -- https://master.php.net/note/delete/88394/spam Del: non-english -- https://master.php.net/note/delete/88394/non-english Del: in docs -- https://master.php.net/note/delete/88394/in+docs Del: other reasons-- https://master.php.net/note/delete/88394 Reject -- https://master.php.net/note/reject/88394 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#149645) next »