How to have PHP display errors? (I've added ini_set and error_reporting, but just gives 500 on errors)

33

So, I don't really have any errors in my current web page, but I want to be able to see an error when they pop up, instead of the HTTP 500 error page. I googled around a bit and thought adding these two lines would fix everything.

ini_set('display_errors', 'On');
error_reporting(E_ALL);

NOTE: I don't have access to the php.ini file, as I'm using my school account's server.

So I introduced a bug (no semicolon after $buggy) like so at the top of my page:

<?php 
ini_set('display_errors', 'On');
error_reporting(E_ALL);
$buggy

$x = 4 + 2;
...

However, I just get a Server error:

"The website encountered an error while retrieving http://mywebpage.com/. It may be down for maintenance or configured incorrectly."

Any ideas?

EDIT:

I've reconfigured my code:

<?php 
include_once 'database/errorSettings.php';
?>
<?php 

$buggy // whoops
$x = 4 + 2;
...

errorSettings.php is the following:

<?php
    ini_set('display_errors', 'On');
    error_reporting(E_ALL);
?>

But it still doesn't work... wrong way to reconfigure?

This question is tagged with php html debugging

~ Asked on 2012-04-10 05:30:47

The Best Answer is


14

What you have is a parse error. Those are thrown before any code is executed. A PHP file needs to be parsed in its entirety before any code in it can be executed. If there's a parse error in the file where you're setting your error levels, they won't have taken effect by the time the error is thrown.

Either break your files up into smaller parts, like setting the error levels in one file and then includeing another file which contains the actual code (and errors), or set the error levels outside PHP using php.ini or .htaccess directives.

~ Answered on 2012-04-10 05:37:43


13

You need to set the error_reporting value in a .htaccess file. Since there is a parse error, it never runs the error_reporting() function in your PHP code.

Try this in a .htaccess file (assuming you can use one):

php_flag display_errors 1
php_value error_reporting 30719

I think 30719 corresponds to E_ALL but I may be wrong.

Edit Update: http://php.net/manual/en/errorfunc.constants.php

int error_reporting ([ int $level ] )
---
32767   E_ALL (integer)     
All errors and warnings, as supported, except of   level E_STRICT prior to PHP 5.4.0.   32767 in PHP 5.4.x, 30719 in PHP 5.3.x, 6143 in PHP   5.2.x, 2047 previously

~ Answered on 2012-04-10 05:34:38


Most Viewed Questions: