请看一下这段代码:
$array = array( 'action' => function () { echo "this works"; } ); class Test { public $array = array( "action" => function () { echo "this doesn't"; } ); }
第一个函数literal解析正常,但第二个 – 类中的一个 – 触发语法错误:
Parse error: Syntax error,unexpected ‘function’ (T_FUNCTION)…
有人可以向我解释一下吗?这是一个错误吗?
编辑:这是最新的PHP:5.6.6
从课堂上来看它是一个属性!
属性规则:
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.
http://php.net/manual/en/language.oop5.properties.php