note 111853 added to function.constant

From: Date: Thu, 04 Apr 2013 18:23:02 +0000
Subject: note 111853 added to function.constant
Groups: php.notes 
Request: Send a blank email to php-notes+get-194340@lists.php.net to get a copy of this message
If you need to access a constant in a subclass from the parent class, you can use get_class <?php class GenericClass{ protected function getConst($key){ return constant(get_class($this)."::".$key); } } class ConstClass extends GenericClass{ Const MY_CONST = "Hello World!"; public function init(){ return $this->getConst('MY_CONST'); } } $cc = new ConstClass(); echo $cc->init(); ?> Output: Hello World! ---- Server IP: 69.147.83.199 Probable Submitter: 67.214.236.178 ---- Manual Page -- http://php.net/manual/en/function.constant.php Edit -- https://master.php.net/note/edit/111853 Del: integrated -- https://master.php.net/note/delete/111853/integrated Del: useless -- https://master.php.net/note/delete/111853/useless Del: bad code -- https://master.php.net/note/delete/111853/bad+code Del: spam -- https://master.php.net/note/delete/111853/spam Del: non-english -- https://master.php.net/note/delete/111853/non-english Del: in docs -- https://master.php.net/note/delete/111853/in+docs Del: other reasons-- https://master.php.net/note/delete/111853 Reject -- https://master.php.net/note/reject/111853 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#194340) next »