Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This isn't really a bug, but more it's result that's not really covered in the documentation. I've done a bit of research and played with a few things myself and I think I've figured it out, but I can't be 100% certain as there's no official text covering this.</p> <p>The impression that I get, is when you attempt to call a static method on an instance, it's the equivelant of using the class name, and PHP will actually call it that way, rather than of the instance. For example <code>$B::getWhy();</code> is the same as <code>B::getWhy()</code>, which is how the core code will see it, whether you pass it an instance or not.</p> <p>The issue you're having is that you're calling a non-static method as a static method. Because of the way methods work, they require a scope to provide such things as <code>self</code> and <code>$this</code>. Now, by calling the non-static method as if it was a static method, and taking into consideration the above about the way PHP will actually run the code, the only scope that is available is that of class <code>A</code> because that's the scope you're calling it from. This means that the late static binding takes place and overrides <code>B::$why</code> with <code>A::$why</code> because of the scope change, which is exactly what late static binding is supposed to achieve.</p> <p>I hope that makes sense, if there are any bits that are unclear, let me know and I'll do my best to explain.</p> <p>For more information, there's another question that actually tackles this: <a href="https://stackoverflow.com/questions/3754786/calling-non-static-method-with">Calling non static method with &quot;::&quot;</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload