Create an array of the whole class constant?

I worked with a class where almost 20 constants are defined, since I want all this constant value in an array, I just want to know

is there any method that creates an array of the whole class constant?

I tried with compact , but it does not work with constants.

class Alpha { const ONE = 'fixone'; const TWO = 'fix_two'; const THREE = 3 public function __construct() { protected $arr_constant = compact(ONE,TWO,THREE); // gives FATAL Error // is there any method which collect all consant and create an array? protected $arr_contact = get_all_constant(__CLASS__); var_dump($arr_constant); } } 
+4
source share
2 answers
 $ref = new ReflectionClass('Alpha'); var_dump($ref->getConstants()); 
+4
source

All Articles