2014-06-22 94 views
1

你好我尝试在一个配置变量PHP错误与配置报告

<?php 

$config['warnings'] = false; 
$config['errors'] = false; 

if (!$config['warnings']) 
{ 
    error_reporting(E_ERROR | E_PARSE); 
} 
if (!config['errors']) 
{ 
    error_reporting(0); 
} 
?> 

但你可以看到当我这样做的另一个开口使用error_reporting声明将取代旧的,以阻止某些事情的error_reporting。我怎样才能阻止,但只有如果booth配置为真,只有一个,如果只有一个配置设置为true?

+0

不应该? – Pogrindis

+0

我想这样做的原因是因为我想编码自己的错误系统 – user3684526

+0

@Pogrindis我不知道该怎么做:/ – user3684526

回答

1

将其作为嵌套逻辑处理。首先检查$config['errors']并启用或禁用error_reportingE_ALL0

error_reporting设置通过调用 error_reporting()内获得的电流值

然后E_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少一点,你可能需要删除您在php.ini管理这个E_DEPRECATEDE_STRICT

if ($config['errors']) { 
    // Enable all (but a little less than all) 
    error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT); 
    // Then check warnings, etc... 
} 
+0

帮了这么多。谢谢! – user3684526

+0

@ user3684526不客气,我很乐意提供帮助。 –