[drupal-devel] testing for NULL or empty variables or array keys

Nedjo Rogers nedjo at gworks.ca
Tue Sep 6 16:35:05 UTC 2005


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