Showing all errors, warnings, notices…
Why would you like to show all errors, warnings, notices, etc? Well, this is the first and easiest way to debug your PHP script. Of course there is a bunch of scripts and debug tools out there, but we do not need sledgehammer to crack a nut, don’t we?
So, first thing is to turn this on on your local or staging server.
Second thing, but even more important!, is to turn it off on your production server!
You don’t want your users to see what is wrong this way.
OK, let’s go to code:
1 2 3 |
<?php error_reporting(E_ALL); ini_set('display_errors', 1); |
And that’s all!
Of course you may need it more complicated way. Something like:
1 2 3 4 5 6 7 8 9 10 |
<?php define( __NAMESPACE__ . '\DEBUG', true ); # (...) if ( defined( DEBUG ) && DEBUG ) { error_reporting(E_ALL); ini_set('display_errors', 1); } else { error_reporting(0); ini_set('display_errors', 0); } |