Your Own PHP File6:59 with Alena Holligan
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.
You need to sign up for Treehouse in order to download course files.Sign up