1

我在常量 (DEPLOYMENT) 的行上遇到解析错误。为什么现在允许这样做,或者我错过了什么。

解析错误:解析错误,期待 `')'' in

class UploadComponent extends Object {

    private $config = array(
        'accessKey' => 'XXXX',
        'secretKey' => 'XXXX',

        'images' => array(
            'bucket' => DEPLOYMENT.'-files/images',
            'dns' => false
        ),

        'files' => array(
            'bucket' => DEPLOYMENT.'-files/files',
            'dns' => false
        ),

        'assets' => array(
            'bucket' => DEPLOYMENT.'-files/assets',
            'dns' => false
        )
    );
    ....
}
4

2 回答 2

7

定义类变量时不能使用变量。而是在构造函数中初始化数组:

class UploadComponent extends Object {

    private $config;

    function __construct() {
        $this->config = array(
            'accessKey' => 'XXXX',
            'secretKey' => 'XXXX',

            'images' => array(
                'bucket' => DEPLOYMENT.'-files/images',
                'dns' => false
            ),

            'files' => array(
                'bucket' => DEPLOYMENT.'-files/files',
                'dns' => false
            ),

            'assets' => array(
                'bucket' => DEPLOYMENT.'-files/assets',
                'dns' => false
            )
        );
    }
}
于 2010-10-14T11:18:26.293 回答
5

原因是“常量”可以动态定义。因此,它们的内容仅在运行时才知道,而不是在编译时知道。

于 2010-10-14T11:20:44.820 回答