Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Why use static instead of self
  • Hi, while looking over the fuel php code I noticed that instead of self::some_method static::some_method is used. This is the first time I see that this can be done. Is there a special reason for using static instead of self or are they the same? Thanks for your answer
  • I believe it is something to do with class inheritance. "static" fixes a long-standing issue with PHP where methods are not properly inherited when using "self". I'm sure someone will give you a more accurate explanation (static is fairly new to me), but hopefully that will point you in the right direction. Edit: It's about "late static bindings": http://php.net/manual/en/language.oop5.late-static-bindings.php It appears to me to be a fix for a broken "self". When class A is based on class B, then self::foo in class B will refer to foo *only ever* in class B, while static::foo in class B will allow class A to override it and provide its own foo. "static" is the equivalent to $this in an object - it looks at the wider picture after inheritance and overriding of methods and properties is resolved.
  • It's about late static binding, which is pretty well explained on php.net. In short: it's about extended classes using the extended methods instead of the originals.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion