【发布时间】:2011-06-09 05:27:56
【问题描述】:
我设置了一个类,简化后是这样的:
class Labels {
static public $NAMELABEL = "Name";
}
我成功让以下代码正常工作:
echo '<table border="1">';
echo '<tr>';
echo "<th>" . Labels::$NAMELABEL . "</th>";
echo '</tr>';
// the rest of the Table code not shown for brevity...
echo "</table>";
当我运行它时,我看到一个带有名为 Name 的列标题的表格 -- 所以它工作正常。
但不是在 heredoc 中——我得到“注意:未定义的变量:C:\xampp........blah blah 中的 NAMELABEL” 当我运行以下命令时:
echo <<<_END
<form action="index.php" method="post"><pre>
Labels::$NAMELABEL : <input type="text" name="author" />
<input type="submit" value="ADD RECORD" />
</pre></form>
_END;
我尝试了各种引用,字符串连接运算符'.',没有任何效果。 我想“好吧,我让静态类变量在 HTML 表中工作, 为什么不是一个heredoc。”
当我喜欢 heredocs,他们有一个奇怪的名字和奇怪的问题。 这是我渴望的那种令人费解的乐趣,heredocs 是 正义的小猴子。
我真的很想在这里使用我的静态类变量——有什么组合吗? 允许我将它们嵌入到我的 heredocs 中的引用/字符串连接?
【问题讨论】:
-
你运行的是哪个版本的 PHP,5.3 还是更早的版本?
-
这是 Heredoc 解析器中长期存在的错误(范围问题)。我今天在搜索有关静态变量 heredoc 解析错误的信息时遇到了这个问题。