Re: use of @ operator to suppress errors

From: Date: Mon, 15 Mar 2004 12:11:53 +0000
Subject: Re: use of @ operator to suppress errors
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-180431@lists.php.net to get a copy of this message
Ben Joyce wrote:
i'm using error_reporting(0) and set_error_handler("MyErrorHandler") to manage my errors but I'm getting situations where a NOTICE error is thrown. For example if I refer to $_GET['this'] when there is no 'this' querystring key then i get the error. I've tried using @$_GET['this'] but it makes no difference. Is this normal?
Yes it is. When you use set_error_handler all errors, warnings and notices cause your handler to be called. To detect the use of the @ prefix check the value of error_reporting in your handler - it will be 0 if @ has been used. Richard Davey wrote:
Yes because @ suppresses the errors on function calls, not variables (which is all $_GET['this'] is).
On the contrary, the @ prefix suppresses all errors for the block of code it precedes where a block is a function or variable. Essentially it sets error_reporting to 0 while it evaluates that block. -- Stuart

« previous php.general (#180431) next »