Turning On and Off Errors2:52 with Alena Holligan
Instead of guessing at what went wrong, let's allow PHP to respond with the errors it encountered. We'll review the error levels and talk about how to display those errors to the screen.
Notice: PHPs way off telling you: "You probably shouldn't be doing what you're doing, but I'll let you do it anyway". Notice errors will not stop the execution of the script. An example of a notice would be when you try to access an undefined variable. Defining a variable before accessing that variable is not required, but it is good practice and could indicate there is something missing.
Warning: PHPs way off telling you: "You’re doing something wrong and it is very likely to cause errors in the future, so please fix it". As with Notice errors, Warning errors will not stop execution of the script. For example: trying to include a file that is missing, or calling a function with the incorrect number of parameters would each produce a warning.
Fatal Error: PHPs way off telling you: "You’ve done something wrong and I don't know how I'm supposed to process this script". Fatal errors are caused when PHP encounters a logical error. There is no issue with the syntax and the script is readable, however, what you’re asking the script to do can't be done. For example: Dividing by zero, trying to access a function that doesn’t exist, or running out of memory. Fatal errors DO stop the execution of the script.
Showing the Errors
There are different locations where we can control what error types are to be reported:
- In the php.ini file
- In the .htaccess file on your web server
- From your own PHP code.
You need to sign up for Treehouse in order to download course files.Sign up