天天看點

php error unexpected,php環境變化引起的"syntax error unexpected $end"

今天修改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