1

I have a custom error handler attached to E_ALL PHP errors.

In an external lib the call $row = @mysql_fetch_assoc($this->result); triggers PHP Warnings caught by my handler. Why? Shouldn't '@' make PHP ignore this?

My question: Is there any way I can detect (in my error handler) that '@' was used?

2 Answers 2

4

Referencing the PHP Manual on set_error_handler shows

It is important to remember that the standard PHP error handler is completely bypassed. error_reporting() settings will have no effect and your error handler will be called regardless - however you are still able to read the current value of error_reporting and act appropriately. Of particular note is that this value will be 0 if the statement that caused the error was prepended by the @ error-control operator.

So you could do this:

function my_error_handler($errno, $errstr) {
  if (error_reporting() == 0) { // called with @
    return;
  }
  //....
}
Sign up to request clarification or add additional context in comments.

Comments

3

A quick look into the PHP manual revealed this:

It is important to remember that the standard PHP error handler is completely bypassed. error_reporting() settings will have no effect and your error handler will be called regardless - however you are still able to read the current value of error_reporting and act appropriately. Of particular note is that this value will be 0 if the statement that caused the error was prepended by the @ error-control operator.

http://de.php.net/manual/en/function.set-error-handler.php

Using the @ operator is considered bad style by quite some people, btw.

1 Comment

There are some entirely valid cases for using @ though, like with unlink() when you don't care if the file exists or not. I'll agree it can be overused but there are definitely valid cases for it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.