note 120195 added to reflectionclass.getconstants

From: Date: Mon, 21 Nov 2016 14:50:13 +0000
Subject: note 120195 added to reflectionclass.getconstants
Groups: php.notes 
Request: Send a blank email to php-notes+get-207254@lists.php.net to get a copy of this message
You can pass $this as class for the ReflectionClass. __CLASS__ won't help if you extend the original class, because it is a magic constant based on the file itself. <?php class Example { const TYPE_A = 1; const TYPE_B = 'hello'; public function getConstants() { $reflectionClass = new ReflectionClass($this); return $reflectionClass->getConstants(); } } $example = new Example(); var_dump($example->getConstants()); // Result: array ( size = 2) 'TYPE_A' => int 1 'TYPE_B' => (string) 'hello' ---- Server IP: 72.52.91.14 Probable Submitter: 81.107.160.225 ---- Manual Page -- http://php.net/manual/en/reflectionclass.getconstants.php Edit -- https://master.php.net/note/edit/120195 Del: integrated -- https://master.php.net/note/delete/120195/integrated Del: useless -- https://master.php.net/note/delete/120195/useless Del: bad code -- https://master.php.net/note/delete/120195/bad+code Del: spam -- https://master.php.net/note/delete/120195/spam Del: non-english -- https://master.php.net/note/delete/120195/non-english Del: in docs -- https://master.php.net/note/delete/120195/in+docs Del: other reasons-- https://master.php.net/note/delete/120195 Reject -- https://master.php.net/note/reject/120195 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#207254) next »