Deciphering PHP Error Messages and Blank Screens

My normal home is Visual Studio, ASP.net (1.1/2.0) and C#, with some CSS, HTML and JavaScript thrown in. Over the past week however, I have been working on an add-on to a client site written in PHP (using mySql as a DB backend).

I am coding in Dreamweaver and am really missing Visual Studio, intellisense, robust debugging, design-time compile, being told right away when I make syntax mistakes and intelligent error messages. Since I have to upload to the test server before trying anything out, I have had to spend too much of my time trying to figure out why errors are occuring, backtracking, commenting out lines, upload and try again.

To save myself some googling in the future, and perhaps to help others in the same quandry, below are some of the most common error messages (or lack thereof) that I experienced during development, along with what they actually mean (since the words themselves rarely tell you what you need to know). If anyone has more to add, put them in the comments and I will add them below.

Parse error: parse error, unexpected $ – You forgot to close all of your brackets. (Or maybe you wrote an open-bracket sign – { – instead of a close-bracket sign)

Completely Blank Screen – This one is the worst. It happens when you mess up php syntax. Note: the syntax error may be on the referenced page, or it may be on some page that you included, or that was included by an include (etc). The best part about it is you have no way of knowing where the error originated since the blank screen conveniently forgets to provide you with any error message. Here are the different things that caused this one to appear for me:

  • Forgot a semi-colon at the end of a line. (This one is the most frustrating, because it is sometimes very hard to find, and because if I was using VS, I would find out about it when I was compiling my site, and not when I was trying to test)
  • Include the word var in a function declaration. For example, the following caused me a few hours of searching to find the cause of my blank screen: “function (var $id) { …” (error is in bold).
  • Include a dollar sign when you aren’t suppossed to. For example: “$name = $account->$Name” causes an error.
  • Not including a dollar sign when you are suppossed to. For example: “for ($i=0; i<count($myArray); $i++) { …” causes an error (missing a dollar sign before the middle i)
  • Forgot a bracket (same as above, sometimes results in error message, sometimes in blank screen)
  • Entered <?php at the beginning of a document instead of <?PHP (stupid case-sensitivity…)

Parse error: parse error, unexpected T_ELSE – In writing an if/else structure, you forgot to include the closing bracket } between the end of if and the beginning of else

Parse error: parse error, unexpected ‘=’ – You forgot to include a $ in front of a variable when making a value assignment. For example: “i = 5;” instead of “$i = 5;”

Tagged . Bookmark the permalink.

One Response to Deciphering PHP Error Messages and Blank Screens

  1. Reuven says:

    My favorite is still “Parse error: parse error, unexpected T_PAAMAYIM_NEKUDOTAYIM”. :-) I’ve gotten that a few times from various typos.

Leave a Reply

Your email address will not be published. Required fields are marked *