php环境变化引起的”syntax error unexpected $end”

2014-04-08 00:00 阅读 340 次 评论关闭

今天修改php配置环境,将php.ini-develop 设为默认的php.ini,之后访问测试web的后台,报错:

Parse error: syntax error, unexpected $end in ……

出错的位置在文件的最后一行,"?>",网上查说是php语言使用不规范引起的,有的地方开头使用"<?php",有的地方用"<?",造成匹配问题。

后来将新的php.ini配置文件删除之后,重启nginx,web服务器恢复正常。

网上查到相同的问题,并附上原因,摘抄如下:

报错的原因是:集成安装环境包默认的情况下不支持 PHP 短标签
解决办法:打开 php.ini ,找到 short_open_tag = Off 这一行,将 Off 修改为 On,保存退出,重启 Apache 就可以了。

详细的错误分析:

In PHP 5, the following error may appears as an error entry in Apache error log or simply displays on PHP web page, even if calling to php scripts with php_info() works perfectly and successfully returns information on PHP configurations:
Parse Error: syntax error, unexpected $end in ….. scripts.php on line …
The error may caused by a missing curly bracket in PHP script coding. Beside, it may also caused by error in PHP coding in class definition, as in PHP, a class definition cannot be broke up and distributed into multiple files, or into multiple PHP blocks, unless the break is within a method declaration.
But more commonly, the error is often caused by the use of Short Open tags in PHP, To use short open tags, it must be enabled in PHP.INI. Search for short_open_tag in PHP.INI, and change the value to On. The line should look line:
short_open_tag = On

版权声明:本文著作权归原作者所有,欢迎分享本文,谢谢支持!
转载请注明:php环境变化引起的”syntax error unexpected $end” | 猎微网

评论已关闭!