I have a php application that I have just re-factored. Unfortunately it spewing out warnings like:
Warning: preg_match() expects parameter 2 to be string, object given in /home/yacoby/dev/netbeans/php/Zend/Db/Select.php on line 776
Which is impossible (or very hard work) to work out the issue as I don't have a callstack so can't tell which parts of my code are causing the warning and there is a lot of code.
I need a method to either treat warnings like errors (In that the application dies and prints the stacktrace) or I need the stacktrace to be shown when printing errors. Is there a method to do this?
See example #1 at http://www.php.net/manual/en/class.errorexception.php
<?php
function exception_error_handler($errno, $errstr, $errfile, $errline ) {
throw new ErrorException($errstr, $errno, 0, $errfile, $errline);
}
set_error_handler("exception_error_handler");
/* Trigger exception */
strpos();
?>
Have a look at set_error_handler()
and include this at the beginning of your scripts or in your bootstrap to just print the stacktrace when E_WARNINGs occur.
function stacktrace_error_handler($errno,$message,$file,$line,$context)
{
if($errno === E_WARNING) {
debug_print_backtrace();
}
return false; // to execute the regular error handler
}
set_error_handler("stacktrace_error_handler");
For more control over the various types, have a look at the more explicit version posted elsewhere in the answers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With