views:

48

answers:

1

In my previous question I found two solutions for accessing static members. I would like to know which one is the better way, and why.

  1. Using reflection
  2. Using object methods
  3. using eval
+1  A: 

In my opinion, if your statis members are public, you should access it directly. Otherwise if it's private or protected, you can access via a method. If you use Reflection to access a static member, the PHP interpreter need some unncessary steps to reflect all member of your object and the process is slower. Another reason to avoid using reflection is you can use code completiong of IDE for improving productivity.

coolkid
in your "Using reflection" link, you have to use reflection because the class name A is dynamic at run time, so there's no other ways for determine its static member name
coolkid
So you mean using object method is good for me? is that faster even when we have few stuffs in class constructor?
KoolKabin
static member of a class is a class member, not an instance member. So it doesn't depend on whether we do in constructor
coolkid