I am a little confused with this matter. I am designing an ORM class that tries to behave very similarly to ActiveRecord in ruby on rails, but that's beside the point.
What I'm trying to say is that my class makes extensive use of static attribute inheritance, specially for database and table handling. My question is, should I use self:: at all?
try to use the code bellow to see the difference between self and static:
and you get this result:
You have to ask yourself: "Am I targeting the problem with the adequated approach?"
self::
andstatic::
do two different things. For instanceself::
or__CLASS__
are references to the current class, so defined in certain scope it will NOT suffice the need of static calling on forward.What will happen on inheritance?
This will print
In the other hand with
static::
It has the expected behaviourThis will print
That is called late static binding in PHP 5.3.0. It solves the limitation of calling the class that was referenced at runtime.
With that in mind I think you can now see and solve the problem adequately. If you are inheriting several static members and need access to the parent and child members
self::
will not suffice.