【发布时间】:2012-02-05 02:11:51
【问题描述】:
假设我的班级中有一个名为 $_staticVar 的静态变量,我正试图像这样访问它。该变量有一个成员aString,其字符串值为"my static variable"
echo <<<eos
<br/>This is the content of my static variable,
self::$_staticVar->$aString
which is not getting accessed properly in heredoc syntax. <br/>
eos;
输出:
注意:未定义变量:/path/to/file.php 中的 _staticVar 位于 some_line_number 行
这是我的静态变量的内容,
self::->我的静态变量,
在 heredoc 语法中无法正确访问。
我试过这个:
echo <<<eos
<br/>This is the content of my static variable,<br/>
{${self::$_staticVar->$aString}}<br/>
which is not getting accessed properly in heredoc syntax. <br/>
eos;
它不起作用。
输出:
注意:未定义变量:/path/to/file.php 中的 _staticVar 位于 some_line_number 行
这是我的静态变量的内容,
在 heredoc 语法中无法正确访问。
这是我的 PHP 设置:
display_startup_errors = 开启
display_errors = 开启
error_reporting = E_ALL | E_STRICT
【问题讨论】:
-
我没有投反对票,而是尝试提供一个更实用的示例。即使对于最有经验的开发人员来说,阅读所有这些“something”和“somevar”真的很枯燥、令人困惑且难以回答!只是一个提示:)
-
@Kieran 我会用其他字符串来改变它。取点。 :)
-
谢谢。我已通过 +1 恢复平衡