__callStatic()
关于PHP 的快速问题;
class Test{
public static function __callStatic($method, $arguments){
echo $method . PHP_EOL;
}
public function __call($method, $arguments){
echo $method . PHP_EOL;
}
}
$test = new Test();
$test->foo();
$test->{'hello-world'}();
Test::bar();
Test::{'goodbye-universe'}();
预期输出:
foo
hello-world
bar
goodbye-universe
实际输出:
foo
hello-world
bar
PHP Parse error: syntax error, unexpected '{', expecting T_STRING or T_VARIABLE or '$' in - on line 18
这种语法是不允许的,也不能用 实现功能__callStatic()
?
注意:试图摆脱没有临时变量。以下将起作用:
$goodbyeUniverse = 'goodbye-universe';
Test::$goodbyeUniverse();
但我试图避免这种情况。