ErrorHandling php
I wrote an error handler to handle different kind of errors in php(even parse errors etc.).
Question:
As I now can detect an errortype(the constant) it is necessary to identify which errors I should allow or not and in which case do a gentle shutdown. If I look at http://www.php.net/manual/en/errorfunc.constants.php I see all the different constants for different kind of errors.
The question is:
1)Is there some kind of relation between these constants for error handling. Lets say above a level I know that I dont want to print the error on my screen etc? Or do I have to set this manually for every error-constant(seems like it)?
2) How to provoke every error on the screen example without using trigger_error() or user_error()? Is there some kind of list to produce those errors and which ones I can produce with code?
Cheers and thanks a lot for answers.
You can group all the notice, warning and error constants together like this:
notice : 8 + 1024 + 2048 + 8192 + 16384 = 27656 0x6c08
warning: 2 + 32 + 128 + 512 = 674 0x2a2
error : 1 + 16 + 64 + 256 + 4096 = 4433 0x1151
You could also add them by explicitly using the constant names, eg E_ERROR
, etc.
So:
$is_notice = $code & 0x6c08 != 0;
$is_warning = $code & 0x2a2 != 0;
$is_error = $code & 0x1151 != 0;
As for your second question, are you looking for code that would trigger the above distinct levels?
$f = fopen($a, 'r'); // notice + warning
$f->read(); // error
include 'script_with_parse_error.php'; // e_parse
function test(Iterator $i) { }
test(123); // e_recoverable_error
function modify(&$i) { ++$i; }
modify(123); // e_strict
$x = split(',', ''); // e_deprecated
The E_USER
events can only be generated with trigger_error()
of course.
上一篇: PHP:PHP错误/警告/通知的双重输出
下一篇: ErrorHandling php