经测试代码如下:
/**
* 遍历类包含的所有元素
*
* @param
* @arrange (512.笔记) jb51.cc
**/
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";
}
/*** 代码来自编程之家 jb51.cc(jb51.cc) ***/