I'm havinh a problem on PHP 5.3. I need to call a method by using __callStatic
, but if I use it in a instancied object, PHP call __call
instead.
Above a real life example:
<?php
class A {
function __call($method, $args){
// Note: $this is defined!
echo "Ops! Don't works. {$this->c}";
}
static function __callStatic($method, $args){
echo 'Fine!';
}
}
class B extends A {
public $c = 'Real Ops!';
function useCallStatic(){
static::foo();
// === A::foo();
// === B::foo();
}
}
$foo = new B();
$foo->useCallStatic();
// This works:
// B::foo();
?>
Prints: Ops! Don't works. Real Ops!
Note that I call useCallStatic
from a new B()
. If I call directly works fine like B::foo()
.
What I can do to it works fine?
See Question&Answers more detail:os