function FriendlyErrorType($type)
{
switch($type)
{
case E_ERROR: // 1 //
return 'E_ERROR';
case E_WARNING: // 2 //
return 'E_WARNING';
case E_PARSE: // 4 //
return 'E_PARSE';
case E_NOTICE: // 8 //
return 'E_NOTICE';
case E_CORE_ERROR: // 16 //
return 'E_CORE_ERROR';
case E_CORE_WARNING: // 32 //
return 'E_CORE_WARNING';
case E_CORE_ERROR: // 64 //
return 'E_COMPILE_ERROR';
case E_CORE_WARNING: // 128 //
return 'E_COMPILE_WARNING';
case E_USER_ERROR: // 256 //
return 'E_USER_ERROR';
case E_USER_WARNING: // 512 //
return 'E_USER_WARNING';
case E_USER_NOTICE: // 1024 //
return 'E_USER_NOTICE';
case E_STRICT: // 2048 //
return 'E_STRICT';
case E_RECOVERABLE_ERROR: // 4096 //
return 'E_RECOVERABLE_ERROR';
case E_DEPRECATED: // 8192 //
return 'E_DEPRECATED';
case E_USER_DEPRECATED: // 16384 //
return 'E_USER_DEPRECATED';
}
return $type;
}
预定义常量
下列常量作为 PHP 核心的一部分总是可用的。
Note: 你可以使用它们在 php.ini 中的常量名称; 但是在PHP之外,例如在 httpd.conf 之中, 你必须使用二进制位掩码来代替。
| 值 | 常量 | 说明 | 备注 |
|---|---|---|---|
| 1 |
E_ERROR
(integer)
|
致命的运行时错误。这类错误一般是不可恢复的情况,例如内存分配导致的问题。后果是导致脚本终止不再继续运行。 | |
| 2 |
E_WARNING
(integer)
|
运行时警告 (非致命错误)。仅给出提示信息,但是脚本不会终止运行。 | |
| 4 |
E_PARSE
(integer)
|
编译时语法解析错误。解析错误仅仅由分析器产生。 | |
| 8 |
E_NOTICE
(integer)
|
运行时通知。表示脚本遇到可能会表现为错误的情况,但是在可以正常运行的脚本里面也可能会有类似的通知。 | |
| 16 |
E_CORE_ERROR
(integer)
|
在PHP初始化启动过程中发生的致命错误。该错误类似
E_ERROR,但是是由PHP引擎核心产生的。
|
since PHP 4 |
| 32 |
E_CORE_WARNING
(integer)
|
PHP初始化启动过程中发生的警告 (非致命错误) 。类似 E_WARNING,但是是由PHP引擎核心产生的。
|
since PHP 4 |
| 64 |
E_COMPILE_ERROR
(integer)
|
致命编译时错误。类似E_ERROR,
但是是由Zend脚本引擎产生的。
|
since PHP 4 |
| 128 |
E_COMPILE_WARNING
(integer)
|
编译时警告 (非致命错误)。类似
E_WARNING,但是是由Zend脚本引擎产生的。
|
since PHP 4 |
| 256 |
E_USER_ERROR
(integer)
|
用户产生的错误信息。类似
E_ERROR, 但是是由用户自己在代码中使用PHP函数 trigger_error()来产生的。
|
since PHP 4 |
| 512 |
E_USER_WARNING
(integer)
|
用户产生的警告信息。类似
E_WARNING, 但是是由用户自己在代码中使用PHP函数 trigger_error()来产生的。
|
since PHP 4 |
| 1024 |
E_USER_NOTICE
(integer)
|
用户产生的通知信息。类似
E_NOTICE, 但是是由用户自己在代码中使用PHP函数 trigger_error()来产生的。
|
since PHP 4 |
| 2048 |
E_STRICT
(integer)
|
启用 PHP 对代码的修改建议,以确保代码具有最佳的互操作性和向前兼容性。 | since PHP 5 |
| 4096 |
E_RECOVERABLE_ERROR
(integer)
|
可被捕捉的致命错误。 它表示发生了一个可能非常危险的错误,但是还没有导致PHP引擎处于不稳定的状态。 如果该错误没有被用户自定义句柄捕获 (参见
set_error_handler()),将成为一个 E_ERROR 从而脚本会终止运行。
|
since PHP 5.2.0 |
| 8192 |
E_DEPRECATED
(integer)
|
运行时通知。启用后将会对在未来版本中可能无法正常工作的代码给出警告。 | since PHP 5.3.0 |
| 16384 |
E_USER_DEPRECATED
(integer)
|
用户产少的警告信息。 类似
E_DEPRECATED, 但是是由用户自己在代码中使用PHP函数 trigger_error()来产生的。
|
since PHP 5.3.0 |
| 30719 |
E_ALL
(integer)
|
E_STRICT出外的所有错误和警告信息。
|
30719 in PHP 5.3.x, 6143 in PHP 5.2.x, 2047 previously |
上面的值(数值或者符号)用于建立一个二进制位掩码,来制定要报告的错误信息。可以使用按位运算符来组合这些值或者屏蔽某些类型的错误。请注意,在 php.ini 之中,只有'|', '~', '!', '^' 和 '&' 会正确解析。
vladvarna at gmail dot com
16-Mar-2012 09:35
frozenfire at php dot net
12-Aug-2011 12:00
Please note that a bug exists in Xdebug versions up to at least 2.1.2 where E_USER_DEPRECATED is not supported even in PHP 5.3.0+.
Andy at Azurite (co uk)
16-Apr-2011 04:15
-1 is also semantically meaningless as a bit field, and only works in 2s-complement numeric representations. On a 1s-complement system -1 would not set E_ERROR. On a sign-magnitude system -1 would set nothing at all! (see e.g. http://en.wikipedia.org/wiki/Ones%27_complement)
If you want to set all bits, ~0 is the correct way to do it.
But setting undefined bits could result in undefined behaviour and that means *absolutely anything* could happen :-)
PhpMyCoder
15-Jul-2010 03:26
Well, technically -1 will show all errors which includes any new ones included by PHP. My guess is that E_ALL will always include new error constants so I usually prefer:
<?php
error_reporting(E_ALL | E_STRICT);
?>
Reason being: With a quick glance anyone can tell you what errors are reported. -1 might be a bit more cryptic to newer programmers.
wolfrageweb.com
01-Oct-2009 03:52
-1 sets the error reporting to show all to include strict. Should only be used for development servers.
