Re: Avoiding NOTICEs on Array References

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 -------------- Original message ----------------------
From: "Tom Rawson" <trawson@xxxxxxxxxx>
> 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?

if (isset($fields['flags']['someflag']) && $fields['flags']['someflag'])
if (isset($_POST['checkboxfieldname'])  && $_POST['checkboxfieldname']) 

The && short-circuits, so the second part of the conditional only gets evaluated if the first part is true.

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux