I ran into some very strange behaviour on PHP5.4 (also present in 5.5). Basically, I am calling a non-static method statically and I am not getting an E_STRICT error where I definitely should be getting one.
<?php
error_reporting(E_ALL);
class A
{
public function iAmNotStatic() {}
}
Now, if I do this:
A::iAmNotStatic();
Then I get the error as expected Strict standards: Non-static method A::iAmNotStatic() should not be called statically
.
And also, if I make the call from object context, I also get the same error (as expected)
class B
{
public function __construct() {
A::iAmNotStatic();
}
}
$b = new B(); // error here, as expected
However, if I do this (assign A to be the parent of B):
class B extends A
{
public function __construct() {
A::iAmNotStatic();
}
}
$b = new B(); // no error
Then PHP decides that "no problem, I have an object ($b) with the same parent class (A), let's just make it the context for iAmNotStatic
".
So, is this a feature or a bug and what might be the purpose of this confusing (undocumented?) behaviour? Thanks :)