PHP错误报告与配置
嗨,我正试图阻止某些错误报告在配置变量上PHP错误报告与配置,php,Php,嗨,我正试图阻止某些错误报告在配置变量上 <?php $config['warnings'] = false; $config['errors'] = false; if (!$config['warnings']) { error_reporting(E_ERROR | E_PARSE); } if (!config['errors']) { error_reporting(0); } ?> 但正如你所看到的,当我做另一个开场错误报告时,它将取代旧的一
<?php
$config['warnings'] = false;
$config['errors'] = false;
if (!$config['warnings'])
{
error_reporting(E_ERROR | E_PARSE);
}
if (!config['errors'])
{
error_reporting(0);
}
?>
但正如你所看到的,当我做另一个开场错误报告时,它将取代旧的一个。如果booth配置为true,并且只有一个配置设置为true,我如何才能阻止,但仅当booth配置为true时才阻止?将其作为嵌套逻辑处理。首先检查
$config['errors']
并使用E\u ALL
或0
启用或禁用错误报告
然后通过调用error\u reporting()
inside从error\u reporting
设置中减去E\u WARNING
,以获得当前值
if ($config['errors']) {
// Enable all
error_reporting(E_ALL);
// Then subtract warnings from the current value
// by calling error_reporting() as its own argument
if (!$config['warnings']) {
error_reporting(error_reporting() & ~E_WARNING);
}
}
else {
// Or disable everything.
error_reporting(0);
}
你没有特别提到E_NOTICE
,但我怀疑你也希望禁用这些功能
error_reporting(error_reporting() & ~E_WARNING & ~E_NOTICE);
如果您希望从略低于E_ALL
的内容开始,您可能希望删除E_DEPRECATED
和E_STRICT
if ($config['errors']) {
// Enable all (but a little less than all)
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT);
// Then check warnings, etc...
}
您不应该在php.ini中管理它吗?我之所以要这样做,是因为我想编写自己的错误代码system@Pogrindis我不知道怎么做:/但你应该写你自己的不?更改sys php.ini vars incode似乎是错误的。@Pogrindis在运行时修改error\u reporting()。