0

I have one weird problem with error_reporting function.

I want to save current error_reporting level, disable error reporting for few lines, and restore it back. So I have following code:

$oldErrorReporting = error_reporting();
error_reporting(0);
//Some code, that will generate warning, or error, that I don't want to show
error_reporting(oldErrorReporting);

So, if I remove last line, there are no errors, and everything works fine. But if I add last line, I got error that happen in code while error reporting was turned off. So, is there any was to clear those errors that happen while error_reporting level was 0, and restore default error reporting level, without those errors that happen while error report was tuned off?

oezi
  • 51,017
  • 10
  • 98
  • 115
Ivica
  • 795
  • 2
  • 8
  • 20
  • Is this literally your code? Then you're missing a `$`. Otherwise, do you know of the error suppression operator `@`? Also, what code do you have that triggers errors? – deceze Apr 16 '12 at 06:51

2 Answers2

1

maybe it's just a typo (if so, please don't rewrite code for a question, just copy&paste (and remove uneccesssary lines)), but you forgot the $-sign in your last line:

error_reporting($oldErrorReporting);
oezi
  • 51,017
  • 10
  • 98
  • 115
1

What kind of code generates warnings? If it is a funciton try instead of lowering the debug level, to suppress the warning itself - write "@" in front of the function name

have a look at:

Suppress error with @ operator in PHP

Community
  • 1
  • 1
xholicka
  • 173
  • 6
  • Problem is with imap_open function, and it generate error, in case that connection with imap server fail for any reason, and I want to avoid that, and just inform user if it is possible to connect to IMAP server or not, without error details. I tried with@ to prevent errors, but it doesn't work as expected. – Ivica Apr 16 '12 at 07:44
  • would you mind posting here importatant parts of code? there are several ways to handle errors...conditions, exceptions etc. – xholicka Apr 16 '12 at 09:13