为什么不能像这样使用 range() ?

ttt*_*ony 0 php

为什么不能range()在这里分配变量?

class foo
{
    //
    // Error
    public static $bar = range(1, 10);

    //
    // Error
    public $bar = range(1, 10);

    //
    // Works
    public static $zoo = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
}
Run Code Online (Sandbox Code Playgroud)

Thi*_*ter 5

您不能使用函数调用的结果来初始化类属性。

array() 是一种语言结构而不是函数,因此它确实有效。