Use ini_set to Display PHP Errors
  Aug 06, 2009

If your host happens to have weird or non-existent PHP logging features, you can easily enable them in-line with your code as if you had changed php.ini directly.

We just need to create a little debugging file that we can later use to include the file we want to debug.

Note that you really do have to include the file! You can not simply paste it on top of the file you want to debug due to the way PHP parses the code.

debug.php

1
2
3
4
5
6
<?php
error_reporting(E_ALL);
ini_set('display_errors','1');
 
include('php_err.php');
?>

The following PHP snippet contains an obvious syntax error (missing curly bracket ending if statement). We can use this to make sure we can see the debug messages is the browser

php_err.php

1
2
3
4
<?php
if (true) {
    echo 'foobar';
?>

Now, when you view debug.php in the browser, the syntax error should be visible in the browser.

Parse error: syntax error, unexpected $end in /home/dfoo/public_html/php_err.php on line 5



Post a New Comment

Name

Message

Security
Code

        (case insensitive & space between words)