note 73628 deleted from language.oop5.constants by felipe

From: Date: Sat, 15 Dec 2007 02:08:46 +0000
Subject: note 73628 deleted from language.oop5.constants by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-133524@lists.php.net to get a copy of this message
Note Submitter: Maikel ---- 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!! ?>

« previous php.notes (#133524) next »