带常量的 PHP 类变量
我在常量 (DEPLOYMENT) 行上收到解析错误。为什么现在允许这样做,或者我错过了什么。
解析错误:解析错误,期望出现“')'”
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
)
);
....
}
I am getting a parse error on the lines with the constant (DEPLOYMENT). Why is this now allowed, or am I missing something.
Parse error: parse error, expecting `')'' 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
)
);
....
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
定义类变量时不能使用变量。相反,请在构造函数内初始化数组:
You can't use variables when defining class vars. Initialize your array inside the constructor instead:
原因是“常量”可以动态定义。因此,它们的内容只能在运行时知道,而不能在编译时知道。
The reason is that 'constants' can be defined dynamically. Their contents are therefore only known at run-time, and not compile-time.