I found this strange behavior 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 follow these steps:
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 fires __call() instead of __callStatic() . I was wondering if this should work like that, or is this some kind of mistake?
[EDIT]
I forgot to try static::bar(); on callMe() , but no, that didn't work either.
I (I think I) understand the comment, but still ... if I call the class itself, and not an instance or object, then for me the logical logic says that it should call __callStatic (). Oh good.
Thanks for your answers / comments.
source share