首先看代码:
以下是引用片段:
杯具了,这句话有语法错误:
以下是代码片段:
private $_expire_time = 60 * 60 * 24 * 7;
那么,这是为什么呢?
以下是引用片段:
Class member variables are called "properties". You may also see them referred to using other terms such as "attributes" or "fields", but for the purposes of this reference we will use "properties". They are defined by using one of the keywords public, protected, or private, followed by a normal variable declaration. This declaration may include an initialization, but this initialization must be a constant value--that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated.
如红色字体,翻译如下:
以下是引用片段:
这个声明可能会包含初始化,当时这个初始化必须是一个定值,也就是说,这个定值必须在编译时就能确定,而不是依赖于php在运行时再确定值。
呃,翻译的有点拗口。简而言之,就是说类里面变量的初始化不能是一个表达式,否则编译期间就编译不过去,产生不了Opcodes。
手册中给出错误和正确的初始化的例子:
以下是代码片段:
// invalid property declarations:
public $var1 = ’hello ’ . ’world’;
public $var2 = <
EOD;
public $var3 = 1+2;
public $var4 = self::myStaticMethod();
public $var5 = $myVar;
// valid property declarations: public $var6 = myConstant;
public $var7 = array(true, false);
// This is allowed only in PHP 5.3.0 and later. public $var8 = <<
hello world
EOD;
}
?>
关于Opcodes和编译的过程,可以参考以下资料:
说句题外话:
不过随便进入文档任意语言页面,切换语言中选 "Other",还是可以进入中文文档的。