note 89065 deleted from language.oop5.constants by tularis

From: Date: Sun, 04 Dec 2011 18:50:06 +0000
Subject: note 89065 deleted from language.oop5.constants by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-184888@lists.php.net to get a copy of this message
Note Submitter: mr dot lukes at gmail dot com ---- How to get good constant when you extend the class: Check this out... <?php class A { private $a; const NAME = "AAA"; public function __construct() { $this->a = "aaa"; } public function myName() { $class = get_class($this); eval("\$a = $class::NAME;"); return $a; } } class B extends A { private $a; const NAME = "BBB"; public function __construct() { $this->a = "bbb"; } } $b = new B(); echo B::NAME; echo "\n"; echo $b->myName(); echo "\n"; ?> Output: BBB BBB

« previous php.notes (#184888) next »