【发布时间】:2015-01-23 09:47:01
【问题描述】:
为什么这是编译错误:
<?php
class Bean
{
public $text = array("123", "456");
public $more = array("000 {$this->text[0]} 000", "--- {$this->text[1]} ---");
}
?>
编译器说PHP Parse error: syntax error, unexpected '"'
如何在其他数组中使用我的文本数组?
【问题讨论】:
-
第 5 行应该是
public $more = array("000 {" . $this->text[0] . "} 000", "--- {" . $this->text[1] . "} ---"); -
这不起作用。我检查了ideone
-
我不认为你可以让它与当前版本的 php 一起工作。尽管在最新的 php 版本中已经删除了一些关于“必须是 const 值”规则的限制......像这样? ……我不这么认为。见php.net/manual/migration56.new-features.php“常量表达式”
-
您应该能够动态填充数组。这很有趣。我想知道为什么这不起作用。