tak*_*eek 3 php error-reporting
是否可以更改我的PHP应用程序包含的文件的错误报告级别(关闭E_STRICT)include或require_once?
我希望能够看到我的代码中出现的严格通知,但我正在使用PEAR MDB2,当我打开E_STRICT时,我从该代码中获得了警告页面.
我知道可以error_reporting使用.htaccess文件在每个目录的基础上进行更改,但我认为这不适用于包含的文件.我尝试将它放在梨文件夹中,但它没有做任何事情.
您可以error_reporting使用在运行时动态更改设置ini_set().这是一个例子:
// your running code using the default error reporting setting
// set the error reporting level for your library calls
ini_set('error_reporting', E_NOTICE);
// make some library calls
// reset the error reporting level back to strict
ini_set('error_reporting', E_ALL & E_STRICT);
// more of your code
Run Code Online (Sandbox Code Playgroud)
您可以定义自定义错误处理程序,并使用该$errfile参数来确定错误的来源.如果路径与包含的库的路径匹配,则禁止显示错误.否则,将其传递给PHP的错误报告.
据我所知,这应该捕获由库引起的任何和所有警告和通知.
因为不需要回溯,所以对于大量触发的消息来说,它甚至可能足够快.
这是未经测试但应该有效,基于手册中的示例:
<?php
// error handler function
function myErrorHandler($errno, $errstr, $errfile, $errline)
{
$library_path = "/path/to/library";
if (substr($errfile,0,strlen($library_path))==$library_path)
/* Don't execute PHP internal error handler */
return true;
else
/* execute PHP internal error handler */
return false;
}
Run Code Online (Sandbox Code Playgroud)