You can globally configure this within your php.ini fileDocs.
It can be done by specifying a file that is being included by all PHP processes with the auto_prepend_file
directiveDocs:
auto_prepend_file "/full/path/to/a/prepend-file.php"
Doing that inside your global php.ini file will ensure that the code inside the prepend file will be always executed. Use it then to register a global error handler that will turn all errors into exceptionsDocs:
<?php
function exception_error_handler($errno, $errstr, $errfile, $errline ) {
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
set_error_handler("exception_error_handler");
This little script will turn all errors/warnings/notices etc. into an ErrorException
.
This code example is likely too short (will comment further below) so don't miss the examples on the set_error_handler()
Docs manual page.
Combine it with the error_reporting
ini directiveDocs, the values are describe in your php.ini file (or as another option use the second parameter for set_error_handler
handle errors by their severity).
Throwing an exception is a very strict thing. Your programmers will be forced to deal with warnings and errors otherwise the code won't not work (including those in code with the @
error control operator, rendering it void).
Probably this is too much and not socially acceptable within the company. Instead you can also log all errors and add them at the end of the output (or at the top so it's more visible) by making use of output buffering.
Creating (but not throwing) the error exception already captures a back-trace which can be useful in error handling.
Another alternative to display the errors and warnings is to log them to the log-file and then monitor that file with another process and aggregate the information. You could create a scoreboard that display the number of warnings per application and make this visible in the office so everybody sees how well a team performs or some fun like that.
What I try to say is: Next to the technical problem, it's a social problem you need to be creative with and actually talk the problem out of your developers. You need to make clear why it's important to fix warnings and errors and how their coding and skills will benefit from that.