According to one of the man pages http://www.php.net/manual/en/language.oop5.static.php :
Calling non-static methods statically generates an E_STRICT level warning.
But, this doesn't seem to be the case when the call is made from inside the class:
error_reporting(-1);
class Test {
private $id;
function __construct($id) { $this->id = $id; }
function id() { return $this->id; }
function __toString() {
return Test::id()
. self::id()
. static::id()
. static::id()
. call_user_func('Test::id')
. call_user_func(array('Test', 'id'));
}
}
$a = new Test('a');
$b = new Test('b');
echo "$a $b $a"; # aaaaaa bbbbbb aaaaaa
var_dump(error_get_last()); # NULL
Testing with php 5.4
DEMO: http://codepad.viper-7.com/IKp9iX
I believe I've demonstrated:
- No E_STRICT warning is generated
- That php magically corrects the static method call to an instance method call(accessing the instance variable
id
proves this).
edit-
I'd like to add that inserting debug_backtrace() into the __toString call yields a call "type" of ->
, which means "method call".
Is this a bug, or a documented feature?