3

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.

7
  • What do you mean by "above a level I know"? The levels are usually notice < warning < error. Commented Jun 10, 2013 at 2:55
  • 1
    I think by "above a level" he's asking if the numeric value of the constant can be used to identify relative criticality of an error. The answer is "no". Commented Jun 10, 2013 at 3:00
  • @talentfrei - The errors you can raise in code are E_ERROR, E_WARNING, E_DEPRECATED, E_NOTICE Commented Jun 10, 2013 at 3:04
  • @jack If I look the link I posted there are a lot more errors than you wrote down. But what Im looking for is some kind of leveling with the error type. Commented Jun 10, 2013 at 3:05
  • @StevenMoseley Allright. Do you also know if there is some kind of list to produce errors? So I can identify these errors without producing everyone on my own? Or which kind of errors can I produce with code(this was implicit in my second question). Commented Jun 10, 2013 at 3:06

1 Answer 1

3

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, e.g. 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.

Sign up to request clarification or add additional context in comments.

6 Comments

yes exacly...second question is how to trigger all possible errors(and which one I can trigger).
@jack...thx a lot. One last question. All the other error you havent listed here are not produceable directly, right? Or do I miss sth (not meaing E_USER)
You could use mysql_escape_string to throw an E_DEPRECATED
@talentfrei I'm not sure how one would be able to produce E_CORE_ errors ... or whether you can even handle them, like failing to load a particular module perhaps.
@jack Yeah...just realized that that these are the only questionmarks in my list. But for my leveling it is definitive a fatal one, of course.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.