PHP 错误:"Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM"


class Foo {
public function bar($thing) {
return $thing * 2;
}
}
echo Foo::bar::(4);

上面的代码显示了此错误:

解析错误:语法错误、意外T_PAAMAYIM_NEKUDOTAYIM

你能告诉我为什么吗?我是 php 的新手。谢谢!

要在没有实例的情况下调用类方法,您需要将其设置为静态。 最后的"::"也太多了。

class Foo {
public static function bar($thing) {
return $thing * 2;
}
}
echo Foo::bar(4);

最新更新