Re: [PHP] use of @ operator to suppress errors

2004-03-15 Thread Richard Davey
Hello Ben,

Monday, March 15, 2004, 11:43:24 AM, you wrote:

BJ For example if I refer to $_GET['this'] when there is no 'this' querystring
BJ key then i get the error.

BJ I've tried using @$_GET['this'] but it makes no difference.

BJ Is this normal?

Yes because @ suppresses the errors on function calls, not variables
(which is all $_GET['this'] is).

It's like saying @$this - i.e. as you can see, it doesn't make sense.

-- 
Best regards,
 Richard Davey
 http://www.phpcommunity.org/wiki/296.html

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



Re: [PHP] use of @ operator to suppress errors

2004-03-15 Thread Tom Meinlschmidt
Yes, it's normal.

You've to check if is that variable set if (isset($_GET['this'])) and than you didn't 
get any
NOTICE about that undefined variable. 

condition if ($_GET['this']) is not sufficient to check whether is variable set or 
not.

/tom

On Mon, 15 Mar 2004 11:43:24 -
Ben Joyce [EMAIL PROTECTED] wrote:

 hi.
 
 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?
 
 Thanks in advance.
 
 Ben
 
 p.s. PHP 4.3.4 on Windows 2003
 
 -- 
 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



Re: [PHP] use of @ operator to suppress errors

2004-03-15 Thread Stuart
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


Re: [PHP] use of @ operator to suppress errors

2004-03-15 Thread Ben Joyce
Richard, Tom, and Stuart... thanks for your responses much appreciated.

I shall now go and fiddle.

Cheers,

Ben

- Original Message - 
From: Tom Meinlschmidt [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, March 15, 2004 12:01 PM
Subject: Re: [PHP] use of @ operator to suppress errors


 Yes, it's normal.

 You've to check if is that variable set if (isset($_GET['this'])) and than
you didn't get any
 NOTICE about that undefined variable.

 condition if ($_GET['this']) is not sufficient to check whether is
variable set or not.

 /tom

 On Mon, 15 Mar 2004 11:43:24 -
 Ben Joyce [EMAIL PROTECTED] wrote:

  hi.
 
  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?
 
  Thanks in advance.
 
  Ben
 
  p.s. PHP 4.3.4 on Windows 2003
 
  -- 
  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


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



Re: [PHP] use of @ operator to suppress errors

2004-03-15 Thread Ben Joyce
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



Re: [PHP] use of @ operator to suppress errors

2004-03-15 Thread Ben Joyce
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



RE: [PHP] use of @ operator to suppress errors

2004-03-15 Thread Ford, Mike [LSS]
On 15 March 2004 12:12, Stuart wrote:

 Ben Joyce wrote:
 
 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.

In fact, to be completely accurate, @ is an operator and suppresses error in
the *expression* to which it applies -- this means you can affect what it
applies to by using parentheses.

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

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