为什么这些Heredoc和Nowdoc会导致错误? [英] Why do these Heredoc and Nowdoc cause errors?
本文介绍了为什么这些Heredoc和Nowdoc会导致错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经找到了一些解决方案,但是不知道发生了什么事...
I've already found some solutions, but can't know what happened...
示例1:
<?php
echo <<< EOD
test
EOD;
示例2:
<?php
echo <<< 'EOD'
test
EOD;
输出1,2:
PHP Parse error: syntax error, unexpected end of file, expecting variable (T_VARIABLE) or heredoc end (T_END_HEREDOC) or ${ (T_DOLLAR_OPEN_CURLY_BRACES) or {$ (T_CURLY_OPEN)
示例3:
<?php
echo <<< EOD
test
EOD;
?>
示例4:
<?php
echo <<< 'EOD'
test
EOD;
?>
示例5:
<?php
echo <<< EOD
test
EOD;
'dummy';
示例6:
<?php
echo <<< 'EOD'
test
EOD;
'dummy';
输出3、4、5、6:
test
推荐答案
在前两个示例中,终止符后面可能有空格,例如
You probably have spaces after the terminator in your first two examples, e.g.
EOD;[space]
与此:
<?php
echo <<<EOL
test
EOL;[space]
我收到您的错误消息,但没有空格,没有错误.不管是否有结束?>
,这都是事实.
I get your error message, but WITHOUT the space, there's no error. And that's true whether there's a closing ?>
or not.
这篇关于为什么这些Heredoc和Nowdoc会导致错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文