Re: PHP newbie question

From: Date: Wed, 10 Jan 2001 19:34:07 +0000
Subject: Re: PHP newbie question
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-33747@lists.php.net to get a copy of this message
This is my weekly flamebait on the subject of unset variables and checking against those. isset() fails on form elements (ie a text box that is left empty) therefore the variable will be set, but it will be set to '' - to check thoroughly you would have to do if(isset($var) && !empty($var)) or, my personal favorite, is the if(strlen($var)) empty() acts really wierd when values are set to 0 and isset() doesn't always catch everything you need done. --Joe On Wed, Jan 10, 2001 at 11:12:56AM -0800, David Tod Sigafoos wrote: > Hello Neil, > > Wednesday, January 10, 2001, 10:33:09 AM, you wrote: > > > >> : <?php if (! $a) print "Hello, World!"; // script 2 ?> > >> > >> $a evaluates to false, the ! reverses it, and it prints "Hello, World!" > > NZ> What is bothering me is the following: if variables that are not assigned > NZ> a value were to evaluate to false then since false is the same as the > NZ> number 1 the following PHP script should print the number 1 but instead > NZ> prints nothing: > > NZ> <?php if (! $a) print $a; ?> > > NZ> How is this behavior justified? > > The operation (! $a) must return something .. true or false. The only > other option would be to crash the system to a debugger with a nasty > message about the developer should have checked the variable cause it > wasn't assigned. > > For this reason if you are unsure about the state try > > If (isset($a) { > If (! $a) { > } > Else { > } > } > > Something like this always works. > > > -- > DSig ````` > David Tod Sigafoos ( O O ) > mailto:dsig@teleport.com _______oOOo__( )__oOOo_______ > > Using 'The Bat' 1.48f > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net --- Joe Stump PHP Programmer www.Care2.com

« previous php.general (#33747) next »