I came across very strange behavior in PHP5.4 (also present in 5.5). Basically, I am calling the non-static method statically, and I am not getting the E_STRICT error, where I definitely should get it.
<?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 a call from the context of the object, I also get the same error (as expected)
class B
{
public function __construct() {
A::iAmNotStatic();
}
}
$b = new B();
However, if I do this (assign A to parent B):
class B extends A
{
public function __construct() {
A::iAmNotStatic();
}
}
$b = new B();
PHP then decides that "no problem, I have an object ($ b) with the same parent class (A), just make it the context for iAmNotStatic."
, (?) ?
:)