net*_*der 19
是的,它正在超载:
class Foo {
public function __call($method, $args) {
echo "$method is not defined";
}
}
$a = new Foo;
$a->foo();
$b->bar();
Run Code Online (Sandbox Code Playgroud)
从PHP 5.3开始,您也可以使用静态方法:
class Foo {
static public function __callStatic($method, $args) {
echo "$method is not defined";
}
}
Foo::hello();
Foo::world();
Run Code Online (Sandbox Code Playgroud)
是的,您可以使用__call魔术方法,该方法在找不到合适的方法时调用.例:
class Foo {
public function __call($name, $args) {
printf("Call to %s intercepted. Arguments: %s", $name, print_r($args, true));
}
}
$foo = new Foo;
$foo->bar('baz'); // Call to bar intercepted. Arguments: string(3) 'baz'
Run Code Online (Sandbox Code Playgroud)