This workshop will be retired on May 1, 2025.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
Turning on error within an individual PHP file can be helpful and quick, especially if you donβt have access to the server, or are just trying to track down an error on one page. This also allows you to override the setting in the php.ini or .htaccess file. You can also suppress errors for a particular line using the @ symbol.
PHP Error Settings
error_reporting(E_ALL);
ini_set("display_errors", 1);
ini_set("html_errors", 1);
WARNING! Be careful that your error handling does not get pushed to production.
This does not work for Parse Errors which stop PHP from processing your code at all. PHP will never even read those error setting lines of code.
Using a php file to debug sytax errors
When you don't have access to your php.ini file, it can be difficult to debug syntax errors since they cause fatal startup errors. You can use the following method to bypass this limitation:
Create a file "syntax.debug.php" with the following code (replace "syntax.php" with the file you want to test):
<?php
error_reporting(E_ALL);
ini_set('display_errors','On');
include('syntax.php');
The 5 line file is guaranteed to be free of errors, allowing PHP to execute the directives within it before including the file which previously caused fatal startup errors. Now those fatal startup errors become run time fatal errors.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up