note 95168 added to reflectionclass.getconstants

From: Date: Wed, 16 Dec 2009 13:39:07 +0000
Subject: note 95168 added to reflectionclass.getconstants
Groups: php.notes 
Request: Send a blank email to php-notes+get-164043@lists.php.net to get a copy of this message
I was trying to determine how to get a var_dump of constants that are within an interface. Thats right, not using any classes but the interface itself. Along my travels I found it quite interesting that the ReflectionClass along with a direct call to the interface will also dump its constants. Perfect!!!! This was using PHP 5.3.1 and my example as below:- 1st File: constants.php <?php <?php> interface MyConstants { // -------------------------- // Programmatic Level // -------------------------- const DEBUG_MODE_ACTIVE = FALSE; const PHP_VERSION_REQUIREMENT = "5.1.2"; } ?> ======= Second file: ======= test.php <?php> include_once ("constants.php"); $oClass = new ReflectionClass ('MyConstants'); $array = $oClass->getConstants (); var_dump ($array); unset ($oClass); ?> what you would get from the command line:- ?:\???\htdocs\????>php test.php array(2) { ["DEBUG_MODE_ACTIVE"]=> bool(false) ["PHP_VERSION_REQUIREMENT"]=> string(5) "5.1.2" But as you can see this can work quite well to your advantage in many ways so I truely hope this helps someone else with a similar headache in the future to come! Enjoy! ---- Server IP: 117.104.162.229 Probable Submitter: 122.111.79.89 (proxied: 122.111.79.89) ---- Manual Page -- http://www.php.net/manual/en/reflectionclass.getconstants.php Edit -- https://master.php.net/note/edit/95168 Del: integrated -- https://master.php.net/note/delete/95168/integrated Del: useless -- https://master.php.net/note/delete/95168/useless Del: bad code -- https://master.php.net/note/delete/95168/bad+code Del: spam -- https://master.php.net/note/delete/95168/spam Del: non-english -- https://master.php.net/note/delete/95168/non-english Del: in docs -- https://master.php.net/note/delete/95168/in+docs Del: other reasons-- https://master.php.net/note/delete/95168 Reject -- https://master.php.net/note/reject/95168 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#164043) next »