[英]PHP Late Static Binding — Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE
Testing some late static binding and getting this error on line 5: 测试一些较晚的静态绑定,并在第5行得到此错误:
Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE
line 5: 第5行:
protected static test = 'A TEST';
Here is the source: 来源如下:
class A {
protected static test = 'A TEST';
public static function test() {
echo $this->test;
}
}
Class B extends A {
public static test = "B TEST";
public function static_test() {
echo static::$test;
}
}
$a = new A;
$b = new B;
echo '$a->test()<br />';
echo $a->test();
echo '<br /> <br />';
echo '$b->test()<br />';
echo $b->test();
echo '<br /> <br />';
echo '$b->static_test()<br />';
echo $b->static_test();
Safe to say I am stumped. 可以肯定地说我很沮丧。
protected static $test = 'A TEST';
^--- !!!
It's not a constant - so it should be preceded by $
sign 它不是常数-因此应在
$
符号之前
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.