References in a class to static class members (fields or methods) can be made using either ``++self::$var++`` or ``++static::$var++`` (introduced in 5.3). The difference between the two is one of scope. Confusingly, in subclasses, the use of ``++self::++`` references the original definition of the member, i.e. the superclass version, rather than any override at the subclass level. ``++static::++``, on the other hand, references the class that was called at runtime.
@Ann, when discovering this rule it was not obvious for me to understand if there was or not a difference between self:: or static:: prefixes to access static functions of fields.
If my understanding is correct, there is no difference but obviously it's better to use static:: to prevent any misunderstanding.
If this is the case, I would associate this rule to the SQALE characteristic Maintainability > Understandability and to the tag pitfal
=== on 14 Oct 2014, 14:43:05 Ann Campbell wrote:
\[~freddy.mallet] I disagree about SQALE - the point of the rule is that when you use ``++self::++`` you're going to get the superclass' version, not the override - i.e. you won't get what you think you will.