note 73628 added to language.oop5.constants

From: Date: Mon, 05 Mar 2007 03:44:19 +0000
Subject: note 73628 added to language.oop5.constants
Groups: php.notes 
Request: Send a blank email to php-notes+get-124079@lists.php.net to get a copy of this message
One way to access class constants from an instance is using the __get method, example: <?php class MyClass { const MY_CONSTANT = "Constant class"; public static function __get($name) { if(defined("self::$name")) { return constant("self::$name"); } trigger_error ("Constant $name isn't defined"); } } $instance = new MyClass(); echo $instance->MY_CONSTANT; //it works!! ?> ---- Server IP: 69.147.83.197 Probable Submitter: 200.109.203.195 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.constants.php Edit -- https://master.php.net/note/edit/73628 Del: integrated -- https://master.php.net/note/delete/73628/integrated Del: useless -- https://master.php.net/note/delete/73628/useless Del: bad code -- https://master.php.net/note/delete/73628/bad+code Del: spam -- https://master.php.net/note/delete/73628/spam Del: non-english -- https://master.php.net/note/delete/73628/non-english Del: in docs -- https://master.php.net/note/delete/73628/in+docs Del: other reasons-- https://master.php.net/note/delete/73628 Reject -- https://master.php.net/note/reject/73628 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#124079) next »