gpt4 book ai didi

php - file_get_contents() PHP 的全局错误处理

转载 作者:可可西里 更新时间:2023-10-31 22:47:55 24 4
gpt4 key购买 nike

我在使用 file_get_contents 时偶尔会遇到错误,它在我的脚本中使用得相当多。我知道我可以使用 @file_get_contents 单独抑制错误,并且可以使用

设置全局错误消息
//error handler function
function customError($errno)
{
echo 'Oh No!';
}

//set error handler
set_error_handler("customError");

但是我该如何专门为所有 file_get_content 的使用设置错误处理程序呢?

谢谢

最佳答案

您可以在调用 file_get_contents 之前设置您的自定义 error_handler,然后在 file_get_contents 之后立即使用 restore_error_handler() 函数。如果在您的代码中多次使用 file_get_contents,您可以通过一些自定义函数包装 file_get_contents。

关于php - file_get_contents() PHP 的全局错误处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6028930/

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