0

以下不起作用:

<?php
class test{
    const t = 10;
    public static $y = array('t' => self::t . 'hello');
}
var_dump(test::$y);
?>

有人能告诉我这是为什么吗?:)

它在 ... => self::t 中失败。'hello')... 部分,作为接缝,它不能在 array() 中连接一个类常量。

这意味着以下两项工作都很完美:

public static $y = array('t' => self::t);

public static $y = array('t' => 'hello');
4

1 回答 1

1

有人能告诉我这是为什么吗?

串联是运行时的产物。类成员初始值必须在解析时已知。

于 2012-04-10T15:54:55.617 回答