note 89065 modified in language.oop5.constants by danbrown

From: Date: Wed, 03 Aug 2011 13:28:34 +0000
Subject: note 89065 modified in language.oop5.constants by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-182174@lists.php.net to get a copy of this message
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 --was-- 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 http://php.net/manual/en/language.oop5.constants.php

« previous php.notes (#182174) next »