Many Thanks Nikolay.

It seems then that if I'm to avoid the NOTICE errors then isset() should be
used as suggested earlier.  Not the greatest solution but a working one.

Thanks to all.

Ben

----- Original Message ----- 
From: "Nikolay Bachiyski" <[EMAIL PROTECTED]>
To: "Ben Joyce" <[EMAIL PROTECTED]>
Sent: Monday, March 15, 2004 2:32 PM
Subject: Re: [PHP] use of @ operator to suppress errors


> ----- Original Message -----
> From: Ben Joyce <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Monday, March 15, 2004 2:04 PM
> Subject: Re: [PHP] use of @ operator to suppress errors
>
>
> > Hmm.  I'm confused.
> >
> > This page...
> > http://uk.php.net/manual/en/language.operators.errorcontrol.php
> >
> > ...says that you can prepend the @ operator to a variable.  So with
> > @$_GET['this'] it should suppress the NOTICE error if 'this' doesn't
> exist.
> >
> > I've done some testing:
> >
> > Test #1
> >
> >     error_reporting(E_ALL);
> >     echo $_GET['test'];
> >
> > This generates an on-screen error.
> >
> > Test #2
> >
> >     error_reporting(E_ALL);
> >     echo @$_GET['test'];
> >
> > The error is suppressed.
> >
> > If I elect to use a custom error handler then i always get an error
> > generated.  It makes no difference what the error level is or whether I
> use
> > the @ operator.
> >
> >     set_error_handler("CustomErrorHandler");
> >     error_reporting(E_ALL);
> >     echo @$_GET['test'];
> >
> >     set_error_handler("CustomErrorHandler");
> >     error_reporting(0);
> >     echo @$_GET['test'];
> >
> >     set_error_handler("CustomErrorHandler");
> >     error_reporting(E_ALL);
> >     echo $_GET['test'];
> >
> >     set_error_handler("CustomErrorHandler");
> >     error_reporting(0);
> >     echo $_GET['test'];
> >
> > They all have the same result.
> >
> > I suppose I could handle this in my error handling function, ignoring
any
> > NOTICE errors, but ideally I'd like to leave it as-is and suppress them

> when
> > referencing.
> >
> > I'm not sure if I'm making much sense.  Any help appreciated!
> >
> > Cheers,
> >
> > Ben
> >
> > ----- Original Message -----
> > From: "Stuart" <[EMAIL PROTECTED]>
> > To: "Ben Joyce" <[EMAIL PROTECTED]>
> > Cc: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
> > Sent: Monday, March 15, 2004 12:11 PM
> > Subject: Re: [PHP] use of @ operator to suppress errors
> >
> >
> > > 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
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
> When you are using set_error_handler, the standart PHP error handler is
> completely bypassed. Both the error_reporting value (saved in php.ini and
> set by the error_reporting() function) and the @ operator will have no
> effect onto your handler. Actually the @ error-control operator just sets
> error_reporting to 0 while the expression to which it is prepeneded is
> interpreted.
>
> Of course you still could fit your handler to use the error_reporting
value
> and take the appropriate action.
>
> Regards,
> Nikolay
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to