Nguyên nhân lỗi PHP – Parse error: syntax error, unexpected $end

administrator

Administrator
Staff member
If you have are using the short form (<? ?> ) for PHP instead of the long form (<?php ?>) you might be faced with this parse error when running your script on different systems:

Parse error: syntax error, unexpected $end in X on line Y

where X is the file path and Y the line number, usually the last line of the file.

To avoid this error, refrain yourself from using the short form and stick to (<?php ?>), despite the extra 3 characters. This will make your code universally accessible and it is essential if your developing for beyond your own personal use. If you insist in using the short form (<? ?> ), and you get this error, you can enable the short form option in the php.ini file.

Keep in mind though, that the short form is supposed to be deprecated in PHP 6. If this goes through you will have to go back and change all your source files.


Việc viết <? ?> và <?php ?> thì không khác nhau, tuy nhiên do một số biên bản sẽ gặp phải lỗi với php cao hơn. Cách fix các bạn hạ phiên bản xuống hoặc cho phép tính năng tuỳ chọn xác định việc cho chạy kiểu viết ngắn <? ?> trong php.ini


Nội dung trong php.ini

; This directive determines whether or not PHP will recognize code between
; <? and ?> tags as PHP source which should be processed as such. It's been
; recommended for several years that you not use the short tag "short cut" and
; instead to use the full <?php and ?> tag combination. With the wide spread use
; of XML and use of these tags by other languages, the server can become easily
; confused and end up parsing the wrong code in the wrong context. But because
; this short cut has been a feature for such a long time, it's currently still
; supported for backwards compatibility, but we recommend you don't use them.
; Default Value: On
; Development Value: Off
; Production Value: Off
; http://php.net/short-open-tag
short_open_tag = Off
; XAMPP for Linux is currently old fashioned
;short_open_tag = On


Mình cũng phải thay đổi cách viết. :(
 
Bên trên