令人费解的 php 解析器错误
好吧,也许不那么令人费解,但就是这样。
我在闲逛时注意到了这一点,在文件中仅输入 ,之后没有空格,只有标签,没有其他任何内容,会引发解析错误。
使用单个空间就可以正常工作。我想知道是否有人知道为什么解析器会阻塞,因为否则省略结束标签是完全可以的。 谢谢。
Ok maybe not so puzzling, but here it is.
I was messing around and noticed this, typing just <?php
in a file, just that, no space after that, nothing else just the tag, throws a parse error.
With a single space it works fine. I was wondering if anyone knows why the parser chokes, since it is perfectly okay otherwise to omit the closing tag.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
PHP 文档 说:
话虽如此,在 PHP 5.3 中,如果您在
php.ini
文件中将short_open_tags
设置为On
,错误仍然会出现。The PHP documentation says:
With that said, in PHP 5.3, if you have
short_open_tags
set toOn
in yourphp.ini
file, the error still shows up.这在 PHP 基本语法文档中得到了回答:
然而,OP似乎允许开始标签+空格(即不是文件中唯一的东西)。此外,从评论来看,发行版或其他补丁版本似乎并非如此。修补。
This answered in the PHP Documentation for Basic Syntax:
However, by the OP it seems that the opening tag + space is allowed (i.e. not the only thing in a file). In addition, from the comments, it would seem that this is not the case for distro versions or otherwised patched.
我的 PHP 版本:
有问题的代码:
在
: 旁边添加更多内容
,
然后添加一个空格:(
最后为空输出)。
对于上面的示例,该 PHP 版本没有给我一个
Parse error:syntax error,unexpected $end
类型的消息,但它确实是这样的:希望它有帮助。在我看来,输入被视为文本,直到
打开序列后面出现空格。
My PHP version:
The code in question:
Adding some more next to
<?php
:or
and then a space:
(finally empty output).
That PHP version is not giving me a
Parse error: syntax error, unexpected $end
type of message for the examples above, but it does with this:Hope it helps. In my eyes this looks like that the input is treated just as text until a whitespace follows up the
<?php
opening sequence.