<?php class Test { const A = ‘1‘; const B = ‘2‘; const C = ‘3‘; const D = ‘4‘; const E = ‘5‘; const F = ‘6‘; public static function all() { $static = new static(); $class = new \ReflectionClass($static); $constants = $class->getConstants(); return $constants; } } var_dump(Test::all()); //打印结果如下: //array (size=6) // ‘A‘ => string ‘1‘ (length=1) // ‘B‘ => string ‘2‘ (length=1) // ‘C‘ => string ‘3‘ (length=1) // ‘D‘ => string ‘4‘ (length=1) // ‘E‘ => string ‘5‘ (length=1) // ‘F‘ => string ‘6‘ (length=1)
原文:http://www.cnblogs.com/spectrelb/p/7833327.html