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

Larry Garfield larry at garfieldtech.com
Fri Oct 14 06:26:13 UTC 2005

+1 on having some recommendations on how to handle these, especially if we 
want to make Drupal E_STRICT compliant.  (I do, anyway. <g>)

Is there some PHP best practices guideline regarding this?  Does PEAR have a 
recommended standard that we could borrow?

On Friday 14 October 2005 02:04 am, Robert Douglass wrote:
> /me blushes and admits the same fuzziness.
> Nedjo Rogers wrote:
> > 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!

Larry Garfield			AIM: LOLG42
larry at garfieldtech.com		ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 

More information about the drupal-devel mailing list