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:[EMAIL PROTECTED] _______oOOo__( )__oOOo_______
> 
> Using 'The Bat' 1.48f
> 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]

---
Joe Stump
PHP Programmer
www.Care2.com


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to