Posted By

ryantxr on 07/11/12


Tagged

class Reflection constants


Versions (?)

Get a list of class constants


 / Published in: PHP
 

Gets the constants from a class using reflection.

  1. class MyTestClass{
  2. const TESTVAR1 = 1001;
  3. const TESTVAR2 = 1002;
  4. const TESTSTR1 = 'hello';
  5. }
  6.  
  7.  
  8. $rc = new ReflectionClass('MyTestClass');
  9. $v = $rc->getConstants();
  10.  
  11. asort($v);// sort by value
  12. //ksort($v);// sort by key
  13.  
  14. foreach ( $v as $name => $value){
  15. echo "$name => $value\n";
  16. }

Report this snippet  

You need to login to post a comment.