RE: [PHP] error with null $HTTP_GET_VARS['field']

From: Date: Wed, 18 Jun 2003 09:51:46 +0000
Subject: RE: [PHP] error with null $HTTP_GET_VARS['field']
Groups: php.general 
Request: Send a blank email to php-general+get-151945@lists.php.net to get a copy of this message
> -----Original Message----- > From: Logan McKinley [mailto:logan@globalweb.net] > Sent: 17 June 2003 19:55 > > right now if a the 'field' key does not exist at all in the > querystring it > returns the following error: > Notice: Undefined index: Register in > c:\inetpub\wwwroot\PHP\Register.php on > line 3 > I think i can use the empty function but i pass in 11 > different variables > and it seems like there must be a more eligant way to prevent > the error then > with 11 individual if statements. Is there a way in which it > will return a > value even if the key does not exist in the querystring. Yes -- you can use the @ silence operator: @$_GET['field'] will silently return NULL if the index 'field' doesn't exist in the $_GET array (or if the $_GET array itself doesn't exist!). Some might regard this as a kludge, but I don't see it that way -- if the operator is provided as part of the language, using it knowledgeably and judiciously seems like a perfectly valid technique to me. 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: m.ford@lmu.ac.uk Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211

« previous php.general (#151945) next »