Debugging PHP Code

Please provide some pointers on debugging PHP code. Having syntax errors in code, displays a completely blank screen and we have no idea where / what the problem is.

1. Having <? php instead of <?php   at the top of the file

2. Having
    $categories[] = array('id' => $row['id'], 'name' => $row['name']); 'selected' => FALSE);
    instead of
    $categories[] = array('id' => $row['id'], 'name' => $row['name'], 'selected' => FALSE);

Who is Participating?
PranjalShahConnect With a Mentor Commented:
You can add this two lines at top of your code..

Aaron TomoskyTechnology ConsultantCommented:
You can stick a die('made it to here');
In you code to check. Put it halfway, see if it makes it. Then keep splitting by Half till you find the problem.
Aaron TomoskyTechnology ConsultantCommented:
You can also use eclipse and have real debugging. But that's a whole other topic.
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

TimBareConnect With a Mentor Commented:
the error reporting is the easiest way to see what line it's dying on, but as far as pointers go, make sure you have the correct number of ()'s around lines, make sure you have your ; at the end of each line, stringing multiple variables together are separated w/ a .
$var1 = "abc";
$var2 = "def";
echo $var1.$var2;

Open in new window

would return "abcdef";

if you're using a for loop, make sure your counter is increasing ($i++;) otherwise it won't ever exit...

look in your web server's log file for the errors, once you've enabled error reporting.

eg. /var/log/apache2/error.log for Ubuntu Linux
      c:\wamp\logs\apache_error.log  windows WAMP install
Placed this at the top of the PHP file to display errors
error_reporting(-1); // Put 0 to remove all errors

Open in new window

Ray PaseurCommented:
Once you get the errors to show up, you will probably be able to find what is wrong rather quickly.  The comment at ID:34928309 is correct.

If you still have trouble debugging after that point, please post the code and the error message.

FWIW, parse errors only show up one-at-a-time.  The parser stops at the first error.  So if you have written a lot of code with a lot of parse errors in it, you may find that you need many iterations to get all the errors out!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.