PHP - Parse error: syntax error, unexpected $end ...
Have you ever had an irritating PHP message that says "parse error" or "syntax" error and little else - and points to $end / the last line of your PHP file which is (a) perfectly ok and (b) probably HTML anyway? Something like this:
Dorothy:~ grahamellis$ php floppy
Parse error: syntax error, unexpected $end in /Users/grahamellis/floppy on line 56
Dorothy:~ grahamellis$
The problem is very likely to be a missing close brace -
} - in other words, an
if or
while, a
function or
class or something similar isn't completed.
How do you find out just where the problem lies in what could be a big file?
a) Think about what you have
just changed since you last ran the PHP - that will give you immediate pointers
b) If you're using an editor such as
vi, my personal trick is to add in an extra
} at the end of my code, then use the
% command to find the matching bracket; it may not be exactly the problem one, but it's a good pointer to the area of concern in the code.
(written 2008-12-23)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
H312 - PHP - Tips and Techniques [789] Hot answers in PHP - (2006-07-02)
[917] Syntax checking in PHP - (2006-11-07)
[1010] Dates, times, clickable diarys in PHP - (2006-12-28)
[1270] PHP Standalone - keyboard to screen - (2007-07-18)
[1649] Easy conversion - image formats, currencies and distances - (2008-05-21)
[1667] Checking server performance for PHP generated pages - (2008-06-06)
[1684] Two PHP include files to make easy web site indexing and navigation - (2008-06-21)
[1983] Keeping PHP code in database and running it - (2009-01-09)
[2025] Injection Attack if register_globals in on - PHP - (2009-02-04)
[2274] PHP preg functions - examples and comparision - (2009-07-08)
[2478] How did I do THAT? - (2009-10-26)
[2981] How to set up short and meaningfull alternative URLs - (2010-10-02)
[4074] A comment on comments in PHP - (2013-04-28)
[4310] Problem ... I want to print a series of numbered forms - (2014-10-05)
[4319] PHP - some quick fixes if scripts have issues, and how to use our support - (2014-11-19)
[4426] FileMaker Day to Unix Time conversion - (2015-02-15)
[4621] The power of scripting - (2016-01-12)
H101 - Introduction to PHP [48] PHP - onwards and upwards - (2004-09-14)
[55] Evening classes to learn PHP - (2004-09-19)
[93] Case Sensitive? - (2004-10-19)
[124] PHP v Java - (2004-11-20)
[132] Portrait of the author - (2004-11-27)
[135] Too many Perls - (2004-11-30)
[317] Programming languages - a comparison - (2005-05-20)
[341] Happy Birthday, PHP - (2005-06-09)
[380] Bridging to the customer requirement - (2005-07-16)
[382] Central London Courses - Perl, PHP, Python, Tcl, MySQL - (2005-07-18)
[433] FTP - how to make the right transfers - (2005-09-01)
[577] Learning to program in Perl or PHP - (2006-01-26)
[624] It's REALLY easy to add a little PHP - (2006-02-26)
[629] Choosing the right language - (2006-03-01)
[646] PHP - London course, Melksham Course, Evening course - (2006-03-14)
[691] Testing you Perl / PHP / MySQL / Tcl knowledge - (2006-04-19)
[712] Why reinvent the wheel - (2006-05-06)
[795] Remember a site's non-technical issues too - (2006-07-07)
[846] Is Perl being replaced by PHP and Python? - (2006-08-27)
[924] The LAMP Cookbook - Linux, Apache, MySQL, PHP / Perl - (2006-11-13)
[949] Sludge off the mountain, and Python and PHP - (2006-11-27)
[1050] The HTML++ Metalanguage - (2007-01-22)
[1198] From Web to Web 2 - (2007-05-21)
[1717] Q - Should I use Perl or Python? - (2008-07-23)
[1753] Perl v PHP, choosing the right language - (2008-08-14)
[2097] PHP Course - for hobby / club / charity users. - (2009-03-22)
[3025] Learning to Program ... in PHP. Course examples. - (2010-11-01)
[4118] We not only teach PHP and Python - we teach good PHP and Python Practice! - (2013-06-18)
Some other Articles
Index Card System for Game Characters in PHPMaking our things easier to findChristmas Survivors-PHP - Parse error: syntax error, unexpected $end ...Why are cooks bad tempered?Images for ChristmasHow to avoid duplicating web page maintainancemod_rewrite for newcomersEnd of Training, 2008