I found this weird behaviour with PHP classes (v5.3.8).
You have:
class foo {
function __call($func, $args) {
if ($func == 'bar')
echo "non-static __call";
}
static function __callStatic($func, $args) {
if ($func == 'bar')
echo "__callStatic";
}
function callMe() {
self::bar();
}
}
Then you do:
foo::bar() // outputs '__callStatic' as expected.
$f = new foo;
$f->callMe(); // outputs 'non-static __call', as I did not expect.
You see, a non-existent static method called from a non-static function triggers __call()
instead of __callStatic()
. I was wondering if this is supposed to work like this or is this some kind of bug?
[EDIT]
I forgot to try static::bar();
on callMe()
but no, it didn't work either.
I (think I) understand inhan's comment but still... if I'm calling the class itself, not the instance or object, immediate logic for me says it should trigger __callStatic(). Oh well.
Thank you for your answers/comments.