title: Why does get_called_class() report wrong result after static call from a different object?
body: <p>I've found some odd behaviour in some legacy code that I am trying to understand.  I have boiled it down to a simple test-case.</p>
  
  <pre><code>&lt;?php
  class Foo {
  
      function DoFoo() {
          print("[" . get_called_class() . "]");
      }
  
  }
  
  class Bar {
  
      function DoBar() {
          Foo::DoFoo();
      }
  
  }
  
  // Called by direct static call.
  Foo::DoFoo();
  
  // Called by indirect static call, without an object context.
  Bar::DoBar();
  
  // Called by indirect static call, from within an (unrelated) object context.
  // (But still, ultimately, a static call).
  $Bar = new Bar();
  $Bar-&gt;DoBar();
  </code></pre>
  
  <p>This code gives the following output:</p>
  
  <blockquote>
    <p><code>[Foo][Foo][Bar]</code></p>
  </blockquote>
  
  <p>However, the description of <a href="https://www.php.net/manual/en/function.get-called-class.php" rel="nofollow noreferrer"><code>get_called_class()</code></a> says that this function <em><code>"Gets the name of the class the static method is called in."</code></em>.  As <code>DoFoo()</code> is always called statically on the <code>Foo</code> class, you would therefore expect <code>get_called_class()</code> to return <code>Foo</code>, in which case you should get the following output:</p>
  
  <blockquote>
    <p><code>[Foo][Foo][Foo]</code></p>
  </blockquote>
  
  <p>Ignore the fact that the above code generates strict standards warnings (these are suppressed in the original code-base) and that the issue being described can be fixed by properly declaring the static functions as <code>static</code> (which is the correct 'solution' to the problem).  What I am interested in, for the sake of my curiosity, is why PHP emits this output in these circumstances.</p>
  
  <p><strong>Is this a PHP bug?</strong><br>
  <strong>If so, why has it never been fixed?</strong><br>
  <strong>Or, if not, what is the rationale for this unintuitive output?</strong></p>
  
  <hr>
  
  <h1>Update</h1>
  
  <p>It has been pointed out in the comments that PHP 7 behaves as described.  This problem therefore only exists between PHP 5.3 (where late static binding was introduced) and 5.6.  <a href="https://3v4l.org/HXq2f" rel="nofollow noreferrer">(demonstration)</a></p>
  
  <p>I would still be interested to know why it took so long to fix it as it seems like an obvious (and, in some cases, critical) mistake, but maybe it was just standard open-source inertia.</p>
  
  <p>If anyone has anything to add in that regard, I'd be happy to accept an answer that provides the information (e.g. link to/summary of a bug report), otherwise I'll close this down in a day or two.</p>