note 89065 added to language.oop5.constants
| From: | mr dot lukes at gmail dot com | Date: | Fri, 20 Feb 2009 04:02:51 +0000 |
| Subject: | note 89065 added to language.oop5.constants | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-150878@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
----
Server IP: 64.71.164.2
Probable Submitter: 24.189.249.176
----
Manual Page -- http://www.php.net/manual/en/language.oop5.constants.php
Edit -- https://master.php.net/note/edit/89065
Del: integrated -- https://master.php.net/note/delete/89065/integrated
Del: useless -- https://master.php.net/note/delete/89065/useless
Del: bad code -- https://master.php.net/note/delete/89065/bad+code
Del: spam -- https://master.php.net/note/delete/89065/spam
Del: non-english -- https://master.php.net/note/delete/89065/non-english
Del: in docs -- https://master.php.net/note/delete/89065/in+docs
Del: other reasons-- https://master.php.net/note/delete/89065
Reject -- https://master.php.net/note/reject/89065
Search -- https://master.php.net/manage/user-notes.php