Posted by Justin Koivisto on 12/19/05 21:00
Bob Stearns wrote:
> I thought that the given expression was always TRUE if "not_there"
> wasn't among the keys (or subscripts if you will) of $_SESSION.
>
> Below find a dump of $_SESSION, a small snippet of code and the results.
> I really don't understand. A new pair of eyes may be able to spot what
> should be an obvious bug.
For me, all the following give the same results: bool(true)
<?php
$ar=array('this'=>3);
var_dump(empty($ar['that']));
$ar=array('this'=>'');
var_dump(empty($ar['this']));
$ar=array('this'=>array());
var_dump(empty($ar['this']));
$ar=array('this'=>NULL);
var_dump(empty($ar['this']));
$ar=array('this'=>0);
var_dump(empty($ar['this']));
$ar=array('this'=>'0');
var_dump(empty($ar['this']));
$ar=array('this'=>FALSE);
var_dump(empty($ar['this']));
?>
However, I never use empty($var) alone, I usually use variations like:
(!isset($var) || empty($var)) // not set or empty
(isset($var) && empty($var)) // set & empty
(isset($var) && !empty($var)) // set & not empty
--
Justin Koivisto, ZCE - justin@koivi.com
http://koivi.com
[Back to original message]
|