sehummel
sehummel

Reputation: 5568

On the fly error reporting in PHP

When our site used to be on IIS hosting with PHP installed, I had error reporting set to E_NONE and was able to turn it on temporarily by using:

ini_set('display_errors', 1);

That command seems to no longer work now that we are on Linux/Apache hosting. I have tried purposely sending bad commands to the server and I get no errors reported.

What am I doing wrong? Is there any other way to temporarily turn on error reporting without having to edit the php.ini each time?

Upvotes: 9

Views: 5094

Answers (3)

Michael
Michael

Reputation: 9283

I just had to do this in one of my scripts. DOMDocument warnings were killing my logs. So, here's what you do:

// First, grab a copy of the current error_reporting level
// while setting the new level, I set it to zero because I wanted
// it off - but you could easily turn it on here
$erlevel = error_reporting(0);
// Then, do stuff that generates errors/warnings
// Finally, set the reporting level to it's previous value
error_reporting($erlevel);

Upvotes: 3

JL235
JL235

Reputation: 2645

The best way to turn on all errors is:

error_reporting( -1 );

This is better than E_ALL, as E_ALL doesn't actually mean all errors in all versions of PHP (it only does in the most recent). -1 is the only way to ensure it's on in all cases.

Upvotes: 3

gen_Eric
gen_Eric

Reputation: 227180

You can change error reporting to E_ALL using the following line:

error_reporting(E_ALL);

Try adding that to the file.

Upvotes: 13

Related Questions