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

Karoly Negyesi karoly at negyesi.net
Fri Oct 14 06:51:09 UTC 2005


On Fri, 14 Oct 2005 08:26:08 +0200, Larry Garfield  
<larry at garfieldtech.com> wrote:

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

Well.

It is well known that these are not the same.

http://www.php.net/manual/en/types.comparisons.php

We have already found that is_null is slower but equals to === NULL so use  
the latter. In the table referenced above !isset always equals to is_null,  
so I propose to use !isset when we want to check for, well, not being set.

if ($foo) and if (isset($foo)) is not the same, often it's a shorthand for  
if(isset($foo) && $foo != 0). I think if(isset($foo) && $foo) will always  
do. Sometimes isset() can be ommited because we know $foo is set.

Regards

NK



More information about the drupal-devel mailing list