gpt4 book ai didi

php - 管理错误和成功消息和代码的好方法是什么?

转载 作者:可可西里 更新时间:2023-10-31 23:44:31 26 4
gpt4 key购买 nike

目前我没有一个很好的系统来管理错误或成功消息,它们几乎是与代码内联编写的。有人可以建议最佳实践或您正在做的事情,以便能够在整个应用程序中正确管理大量错误和成功消息。

考虑国际化......一些应用程序会有语言文件,然后应用程序只是从特定文件中提取字符串......我正在考虑为错误和成功消息实现类似的概念并且很好奇其他人做了什么沿着同样的路线?

最佳答案

这是我使用的一个函数:

function checkErrors($type, $msg, $file, $line, $context) {
echo "<h1>Error!</h1>";
echo "An error occurred while executing this script. Please contact the <a href=mailto:webmaster@somedomain.com>webmaster</a> to report this error.";
echo "<p />";
echo "Here is the information provided by the script:";
echo "<hr><pre>";
echo "Error code: $type<br />";
echo "Error message: $msg<br />";
echo "Script name and line number of error: $file:$line<br />";
$variable_state = array_pop($context);
echo "Variable state when error occurred: ";
print_r($variable_state);
echo "</pre><hr>";
}
set_error_handler('checkErrors');

它将为您提供 PHP 代码产生的所有错误和警告,并在有人访问包含错误的页面时为您创建一个错误页面。

希望这对您有所帮助!

关于php - 管理错误和成功消息和代码的好方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1128648/

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