note 111853 deleted from function.constant by aharvey

From: Date: Mon, 08 Apr 2013 01:24:55 +0000
Subject: note 111853 deleted from function.constant by aharvey
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-194379@lists.php.net to get a copy of this message
Note Submitter: jlwarren1 at gmail dot com ---- 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!

« previous php.notes (#194379) next »