Re: empty() problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I use this function which I find is very useful:

function isEmpty( & $var )
{
    return isset($var) && strlen(trim($var)) == 0;
}


On Sun, 12 Dec 2004 10:12:34 -0500, John Holmes
<holmes072000@xxxxxxxxxxx> wrote:
> Ahmed Abdel-Aliem wrote:
> 
> 
> > Hi Group Members
> > i have a problem with function empty()
> > i use it to check if user entered the form fields and store it in array
> >
> > for example :
> >
> > if (empty($Game_rating))
> >       $errors[] = "You didn't enter the Online Status for the Game.";
> >
> > the problem when the user enters 0 in the form field
> > the empty function returns the error.
> 
> Is $Game_rating supposed to be an integer? If so, then make it one and
> check for <= to zero.
> 
> if(!isset($_Game_rating) || (int)$Game_rating <= 0)
> { $errors[] = "You didn't enter the Online Status for the Game."; }
> 
> Now you _know_ $Game_rating is an integer above zero and is safe to
> display and/or put into a query.
> 
> Simply checking for
> 
> if($Game_rating == '')
> 
> will throw notices on some setups about an undefined variable (depending
> upon error_reporting level) and will allow text through when it's
> supposed to just be an integer.
> 
> --
> 
> ---John Holmes...
> 
> Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
> 
> php|architect: The Magazine for PHP Professionals â www.phparch.com
> 
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 


-- 
Craig Slusher
Web Programmer
cslush@xxxxxxxxx

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux