Return to Snippet

Revision: 58361
at July 11, 2012 04:41 by ryantxr


Initial Code
class MyTestClass{
   const TESTVAR1 = 1001;
   const TESTVAR2 = 1002;
   const TESTSTR1 = 'hello';
}


$rc = new ReflectionClass('MyTestClass');
$v = $rc->getConstants();  

asort($v);// sort by value
//ksort($v);// sort by key

foreach ( $v as $name => $value){
   echo "$name => $value\n";
}

Initial URL

                                

Initial Description
Gets the constants from a class using reflection.

Initial Title
Get a list of class constants

Initial Tags
class

Initial Language
PHP