将警告视为错误 [英] Treating Warnings as Errors

查看:106
本文介绍了将警告视为错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个刚刚重构的PHP应用程序。不幸的是,它发出了如下警告:

I have a php application that I have just re-factored. Unfortunately it spewing out warnings like:


警告:preg_match()期望参数2为字符串,在/ home / yacoby / dev中给出的对象/netbeans/php/Zend/Db/Select.php在776行上

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?

推荐答案

请参见示例#1,网址为 http://www.php.net/manual/en/class.errorexception.php

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();
?>

这篇关于将警告视为错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆