I guess there may not be any difference but personal preference, but when reading various PHP code I come across both ways to access the methods class.
What is the difference:
class Myclass
{
public static $foo;
public static function myMethod ()
{
// between:
self::$foo;
// and
MyClass::$foo;
}
}
With self you can use it within the class and with the "MyClass", as you have, you can reference it externally:
(Note: the initial version said there was no difference. Actually there is)
There is indeed a small diference.
self::
forwards static calls, whileclassName::
doesn't. This only matters for late static bindings in PHP 5.3+.In static calls, PHP 5.3+ remembers the initially called class. Using
className::
makes PHP "forget" this value (i.e., resets it toclassName
), whileself::
preserves it. Consider: