note 98767 modified in function.isset by danbrown

From: Date: Wed, 07 Jul 2010 15:06:05 +0000
Subject: note 98767 modified in function.isset by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-170761@lists.php.net to get a copy of this message
Keep in mind that an empty string is not null, and an empty GET or POST field returns an empty string instead of NULL, thus... file.php?foo <?php $a = ''; $b = NULL; isset($a); // => TRUE isset($b); // => FALSE (isset($a) && $a === ''); // => TRUE ?> With that in mind, one probably would use isset() to check if a variable has been declared somehow and it's value is not the special value NULL. If you want to check if the value is an empty string, it's probably a better idea to check it literally: <?php (isset($a) && $a == '') // => TRUE ?> --was-- Keep that an empty string is not null, and an empty GET or POST field returns an empty string instead of NULL, thus... file.php?foo <?php $a = ''; $b = NULL; isset($a); // => TRUE isset($b); // => FALSE isset($_GET['foo']); // => TRUE ?> With that in mind, one probably would use isset() to check if a variable has been declared somehow and it's value is not the special value NULL. If you want to check if the value is an empty string, it's probably a better idea to check it literally: <?php (isset($a) && $a == '') // => TRUE ?> http://php.net/manual/en/function.isset.php

« previous php.notes (#170761) next »