Php: How to list static fields/properties through reflection? -


let's have class:

class example {         public static $foo = array('id'=>'foo', 'length'=>23, 'height'=>34.2);     public static $bar = array('id'=>'bar', 'length'=>22.5, 'height'=>96.223); } 

how use reflection list of static fields? (something array('$foo', '$bar')?)

you'll want use [reflectionclass][1]. getproperties() function return array of reflectionproperty objects. reflectionproperty object have isstatic() method tell whether property static or not , getname() method return name.

example:

<?php  class example {         public static $foo = array('id'=>'foo', 'length'=>23, 'height'=>34.2);     public static $bar = array('id'=>'bar', 'length'=>22.5, 'height'=>96.223); }  $reflection = new reflectionclass('example');  $properties = $reflection->getproperties(); $static = array();  if ( ! empty($properties) )   foreach ( $properties $property )     if ( $property->isstatic() )       $static[] = $property->getname();  print_r($static); 

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -