gpt4 book ai didi

php - 为什么 @ 运算符不会在 CodeIgniter 中抑制 E_NOTICE?

转载 作者:行者123 更新时间:2023-12-03 07:40:02 24 4
gpt4 key购买 nike

我保证,我知道最好不要忽略错误。运行 XML-Sitemaps 生成器会点击没有有效 session 信息的 URL 来取悦 CodeIgniter。结果是每个被抓取的页面都有一个 E_NOTICE 和一个让我疯狂的日志(和电子邮件通知)。没有任何问题,也没有人或机器人受到伤害——只有我的理智受到影响。

一些人已经为 CodeIgniter unserialize() 失败设计了修复程序:

我已经运行了每个前提,但仍然收到数百条以下通知:

NOTICE: unserialize() [<a href='function.unserialize'>function.unserialize</a>]: Error at offset 98 of 128 bytes

这让我回到原点,提出一个非常简单的问题。这是 CI 的 Session.php 中有问题的第 724 行:

$data = @unserialize(strip_slashes($data));

我没有添加抑制性的“@”——它已经存在了。这是否意味着它会在抛出时专门抑制 E_NOTICE 消息?如果不是,那条线怎么可能产生所有这些让我想把我的头发都扯掉的通知?

最佳答案

设置自定义错误处理程序会绕过 PHP 的错误处理 — 显然还有 PHP 的错误抑制:

It is important to remember that the standard PHP error handler is completely bypassed for the error types specified by error_types unless the callback function returns FALSE. error_reporting() settings will have no effect and your error handler will be called regardless - however you are still able to read the current value of error_reporting and act appropriately. Of particular note is that this value will be 0 if the statement that caused the error was prepended by the @ error-control operator.

<?php
set_error_handler(function ($errno, $errstr) {
echo $errstr;
}, E_ALL);
@unserialize("foo"); // Still shows $errstr!

这将接管 PHP,并且可能会忽略您的错误抑制设置。有可能 CodeIgniter 使用它自己的错误处理程序(我相信它有)并且不管错误抑制级别如何都吐出错误。

但是,PHP 似乎暗示检查错误报告级别并查看它是否等于零将告诉您错误是否应该被抑制。因此,理论上,您可以编辑 CodeIgniter 错误处理程序并添加一个 if (error_reporting()) {/* show error */}

关于php - 为什么 @ 运算符不会在 CodeIgniter 中抑制 E_NOTICE?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12219351/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com