note 125286 added to language.oop5.static

From: Date: Wed, 19 Aug 2020 13:20:38 +0000
Subject: note 125286 added to language.oop5.static
Groups: php.notes 
Request: Send a blank email to php-notes+get-214993@lists.php.net to get a copy of this message
I used instantiation to access the access the a static property directly. A Simple ticky art, you may apply (using object to access static property in a class) with the scope resolution operator <?php class Shopinson { const MY_CONSTANT = 'the value of MY_CONSTANT '; } class Godwin extends Shopinson { public static $myconstant = ' The Paamayim Nekudotayim or double-colon.'; public function SaySomething(){ echo parent::MY_CONSTANT .PHP_EOL; // outputs: the value of MY_CONSTANT echo self::$myconstant; // outputs: The Paamayim Nekudotayim or double-colon. } } $my_class = new Godwin(); print $my_class::$myconstant; $my_class::SaySomething(); echo Godwin::$myconstant; Godwin::SaySomething(); ?> print $my_class::$myconstant; ---- Server IP: 45.112.84.4 Probable Submitter: 103.51.166.36 (proxied: 105.112.101.136) ---- Manual Page -- http://php.net/manual/en/language.oop5.static.php Edit -- https://master.php.net/note/edit/125286 Del: integrated -- https://master.php.net/note/delete/125286/integrated Del: useless -- https://master.php.net/note/delete/125286/useless Del: bad code -- https://master.php.net/note/delete/125286/bad+code Del: spam -- https://master.php.net/note/delete/125286/spam Del: non-english -- https://master.php.net/note/delete/125286/non-english Del: in docs -- https://master.php.net/note/delete/125286/in+docs Del: other reasons-- https://master.php.net/note/delete/125286 Reject -- https://master.php.net/note/reject/125286 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#214993) next »