在set_error_handler()之后,error_get_last()返回null. PHP 7.0 [英] error_get_last() returns null after set_error_handler(); php 7.0

查看:81
本文介绍了在set_error_handler()之后,error_get_last()返回null. PHP 7.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下一个代码:

$a["x"];//should trigger notice
var_dump(error_get_last());//return the error array

运行完美,并返回错误数组. 但是当我使用set_error_handler时,它返回null

runs perfectly and returns an error array. but when I use set_error_handler it returns null

function _do_nothing(){}
set_error_handler('_do_nothing');

$a["x"];//should trigger notice
var_dump(error_get_last());//return null

此代码在3个月前更改为PHP7的PHP5.4上完美运行,此后我在error_get_last()中获取了空值 我正在使用关机功能来检查是否发生了错误,是否将其发送给开发人员.

This code works perfectly on PHP5.4 I had changed 3 month ago to PHP7 and since then I am getting nulls in error_get_last() I am using a shutdown function to check if an error has occured and if so to send it to the developer.

  1. 是否有办法使此代码在PHP7中运行?并让error_get_last()与set_error_handler()一起使用?
  2. 还有其他解决方法吗?并让关机功能得到最后一个错误?我正在使用CodeIgniter,并且不希望破解其内部代码.

推荐答案

这是正常现象,因为在您的示例中,错误已由_do_nothing()函数处理,因此error_get_last()返回null

This is normal behavior because in your example the error is already handled by the _do_nothing() function, so the error_get_last() returns null

如果您删除set_error_handler('_do_nothing'),该错误将不再得到处理,您将再次得到上一个错误

if you remove set_error_handler('_do_nothing') the error won't be handled anymore and you will get the last error again

function _do_nothing(){}
//set_error_handler('_do_nothing');

$a["x"];//should trigger notice
var_dump(error_get_last());//return array() "Undefined variable: a"

此行为在PHP5中与在PHP7中相同

This behavior is the same in PHP5 as in PHP7

这篇关于在set_error_handler()之后,error_get_last()返回null. PHP 7.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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