
Var_dump() is a native PHP function which displays structured, humanly readable, information about one (or more) expressions. The most common fatal error is an undefined class or function and the error generated normally points straight to the root of the problem:įatal error: Call to undefined function create() in /Document/Root/example.php on line 23 Using var_dump() to Aid Your Debugging Your syntax is correct, you’re speaking its language but PHP doesn’t have what it needs to comply. What it means, in short, is that PHP understands what you’ve asked it to do but can’t carry out the request. Fatal Errorsįatal Errors sound the most painful of the four but are in fact often the easiest to resolve.

Without the notice our likely first stop would have been the database record, followed by tracing back through our logic to eventually find our omission in the SQL. In this case, the notice has helped us rule out a potential issue which has in turn steered us towards the likely source of our problem. However, perhaps we should check our SQL statement to ensure we’ve actually retrieved the user’s first name from the database. PHP has helpfully told us that the FirstName key is undefined so we know that this isn’t a case of the database record being NULL. In this instance the notice you receive can really help. However, when you echo $aUserDetails on line 55 there’s no output and PHP throws the notice above. For presentation in your view you’ve assigned the details to an array called $aUserDetails. Say you’ve done a simple database query and pulled a row of user data from a table. This information can be extremely useful in debugging your application. Notice: Undefined index: FullName in /Document/Root/views/userdetails.phtml on line 55
#CODA 2 PHP DEBUGGING CODE#
So, to ensure notices are displayed, set your error reporting level either in your php.ini or amend your runtime code to look like this: Notices are generated by PHP whether they are displayed or not, so deploying code with twenty notices being generated has an impact upon the overhead of your site. As default PHP 4 and 5 do not show PHP notices which can be important in debugging your code (more on that shortly). Next, you will need to set an error reporting level. It is generally considered good practice to do so in files which contain only PHP code in order to avoid accidental injection of white space and the all too common “headers already sent” error.

This can be done either in your php.ini file or at the head of your code like this:


First, you should turn display_errors on. This is normally caused by a syntax error on a platform where the developer has not done their ground work properly. So, with that in mind lets talk about the all too common “I’m getting no error message” issue. In a live environment you neither want to confuse a genuine user or give malicious users too much information about the inner-workings of your site. This probably isn’t such a great idea, however, on your production server(s). For example, it is generally good practice to turn on a verbose level of error reporting on your development platform. It is important that you configure PHP correctly and write your code in such a way that it produces meaningful errors at the right time. This article breaks down the fundamentals of debugging in PHP, helps you understand PHP’s error messages and introduces you to some useful tools to help make the process a little less painful. If you want to build killer web apps though, it’s vital that you understand the process thoroughly. Nobody enjoys the process of debugging their code.
