Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP错误报告与配置_Php - Fatal编程技术网

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()。