Re: Avoiding NOTICEs on Array References
| From: | Jochem Maas | Date: | Wed, 26 Jan 2005 19:54:55 +0000 |
| Subject: | Re: Avoiding NOTICEs on Array References | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-207411@lists.php.net to get a copy of this message | ||
Tom Rawson wrote:
I have many places where I use references like this: if ($fields['flags']['someflag']) ... or perhaps if ($_POST['checkboxfieldname']) ... If there is no value for 'someflag', or if the check box was not checked -- both of which are often the case -- these generate errors at level E_NOTICE. Is there any way to prevent references to missing array elements from generating errors without turning off all E_NOTICE notifications?the answer is to write code that doesn't produce notices. which means checking the vars (array items) exist before using them. use of isset() may help you - isset() shouldn't give a notice if you are checking for an item in an array and it doesn't exist - I say "shouldn't" because I half remember reading about someone having that very problem, I can't remember whether it was bogus or a bug in their version of php. a cousin of isset() is empty() which is not a function as I undertstand it but a language construct, and will also be of help here I think.
Thanks, -- Tom