Re: Avoiding NOTICEs on Array References

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

 



trlists@xxxxxxxxxx wrote:
On 26 Jan 2005 Jennifer Goodie wrote:


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.


I know I can use isset, it just adds a bunch of extra code. I like to find minimal solutions to these things if possible as they are easier to read, and faster to execute.

--
Tom

As already suggested, isset() and empty() are good choices here. Which one you choose it dependent on what exactly your truth table is. Or, it might work better for you to use !isset() or even !empty().


if (!empty($_POST['checkboxfieldname']) {
  /** do stuff */
}

--
Teach a man to fish...

NEW? | http://www.catb.org/~esr/faqs/smart-questions.html
STFA | http://marc.theaimsgroup.com/?l=php-general&w=2
STFM | http://www.php.net/manual/en/index.php
STFW | http://www.google.com/search?q=php
LAZY | http://mycroft.mozdev.org/download.html?name=PHP&submitform=Find+search+plugins


--
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