You are here: Re: My mind is going? empty($_SESSION["not_there"]) « PHP Programming Language « IT news, forums, messages
Re: My mind is going? empty($_SESSION["not_there"])

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация