Commenting Out Sections of Code Helps PHP Troubleshooting

Posted on 28 April 2008 by LizzyFin

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

Yesterday, at the end of a long day in front of this machine I could not for the life of me find the cause of this error:

"Parse error: syntax error, unexpected $end in"
my file on the last line. Now, I recognize that probably means I left out or hastily copied over a quote mark or left the semi-colon off the end of a php statement.

While 512 lines is no huge file, scanning those umpteen lines for a missing character was futile even though I looked at every line at least three times. Then it occurred to me to do what all good thinkers do…let my mind wander! It’s a trick that more people should know about, where you leave the problem at hand and free your mind of it for the time being. Miraculously, a solution will present itself. Michael, where ever you are, thanks for the tip!

Coming back to the issue this morning, I figured that I could “comment out” large portions of the code to isolate the problem. At first I started to comment out entire areas of the php by using <!–– ––> around the html portions that contained the php statements, but that didn’t work. Then, I realized that I should be commenting out portions of the php, so I used /* */ around smaller and smaller sections of the php code and finally found my error, a missing endif.

Comments come in handy for troubleshooting php!

Leave a Reply