[drupal-devel] PHP 101: isset() does not check for zero length(empty) strings

Nedjo Rogers nedjo at gworks.ca
Fri Oct 14 02:43:30 UTC 2005


Awhile back I posted a similar question, see below.  We have a need for some 
standard guidelines on when to use which test for empty, null, or set 
variables, arrays, and object properties.
_______

I find I'm sometimes not sure which types of test I should apply to test if
a variable (or array key) is null or empty.

Looking at the code, I see various usages:

if (is_null($variable))
if (empty($variable))
if ($variable == NULL)
if ($variable === NULL)
if ($objectname->propertyname)
if (array_key_exists($key, $arrayname))
if ($arrayname['key'])
etc.

Can anyone point to or suggest a limited set of tests that we should use,
and guidelines for when each should be applied?  This would be a useful
addition to the coding standards, http://drupal.org/node/318.  Thanks!




More information about the drupal-devel mailing list