问题描述
我有一个刚刚重构的PHP应用程序。不幸的是,它发出了如下警告:
I have a php application that I have just re-factored. Unfortunately it spewing out warnings like:
这是不可能(或很难完成)的该问题是因为我没有调用堆栈,所以无法分辨代码的哪一部分引起了警告,并且有很多代码。
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?
推荐答案
请参见示例#1,网址为
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();
?>
这篇关于将警告视为错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!