RE: [PHP] isset()

From: Date: Sat, 24 Feb 2001 16:18:42 +0000
Subject: RE: [PHP] isset()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-41490@lists.php.net to get a copy of this message
in my preceding email I've written: if($var!='') will fix your all your worries without an intervention of a strings function. Sincerely, Maxim Maletsky Founder, Chief Developer PHPBeginner.com (Where PHP Begins) maxim@phpbeginner.com www.phpbeginner.com -----Original Message----- From: Joe Stump [mailto:jstump@zebulon.miester.org] Sent: Sunday, February 25, 2001 1:09 AM To: PHPBeginner.com Cc: php-general@lists.php.net Subject: Re: [PHP] isset() For the last time - put an input box on a page and submit with NOTHING in the box. Now I want SOMETHING in that box (like a name) - isset() will return true even though it's empty. --Joe On Sat, Feb 24, 2001 at 04:32:11PM +0900, PHPBeginner.com wrote: > Whatever they input is not the objects, right? > > then (I've just double-checked it, to be sure I am not saying some 'BULL') > > > $var = 0; > > if($var) > echo '<P>var matched'; > > if(isset($var)) > echo '<P>var is set'; > > > when the $var is 0 the second condition will return true, the first will be > false instead... > Obviously if they enter anything else then 0 and NULL (I mean nothing) it > will return true in both cases, if($var.., if(isset($var... if(strle($var > ... > > What's wrong with isset() in here? > I am on PHP4.0.4! > > explain me again, why on user input strlen() would do better then isset() ? > > > Sincerely, > > Maxim Maletsky > Founder, Chief Developer > > PHPBeginner.com (Where PHP Begins) > maxim@phpbeginner.com > www.phpbeginner.com > > > > > > -----Original Message----- > From: Joe Stump [mailto:jstump@zebulon.miester.org] > Sent: Saturday, February 24, 2001 4:25 PM > To: PHPBeginner.com > Cc: php-general@lists.php.net > Subject: Re: [PHP] isset() > > > You're wrong in saying that you "usually know what the variable will be" - > you > never know what it's going to be. You aren't entering it.... you need to > remember that mostly idiots are inputting the data :O) > > --Joe > > On Sat, Feb 24, 2001 at 04:17:02PM +0900, PHPBeginner.com wrote: > > have I said it won't work, Joe? > > > > I said that using strlen() might not be necessary. (re-read my post) > > On my own opinion the same things could be done without using the string > > functions. > > Am I wrong in something there? then thanks for correcting me - will know > it > > for the feature. > > > > > > Sincerely, > > > > Maxim Maletsky > > Founder, Chief Developer > > > > PHPBeginner.com (Where PHP Begins) > > maxim@phpbeginner.com > > www.phpbeginner.com > > > > > > > > > > -----Original Message----- > > From: Joe Stump [mailto:jstump@zebulon.miester.org] > > Sent: Saturday, February 24, 2001 4:17 PM > > To: PHPBeginner.com > > Cc: php-general@lists.php.net > > Subject: Re: [PHP] isset() > > > > > > You are COMPLETELY wrong here. isset() is designed to check if a variable > is > > SET - NOT if it has something in it. empty() is designed for strings NOT > for > > ints - so if it's set to 0 it will fail. Finally in PHP 4 + you have > > problems > > when you do checks and variables aren't set. > > > > I do this, like I said before, because the extra 1 billionth of a second > is > > worth the overhead. I've programmed for sites ranging from a few hundered > > hits > > a day to a few million hits a day and this works ALL the time. > > > > --Joe > > > > On Sat, Feb 24, 2001 at 03:15:59PM +0900, PHPBeginner.com wrote: > > > I don't agree with you in here, > > > > > > you usually know what kind of variable you're checking, so strlen() will > > > work just as well as > > > > > > $var ? 'OK' : 'Empty' > > > > > > will work or the isset() - common, it was made for checking the > > variables - > > > use it. > > > > > > strlen() is in fact an overhead, why would you allow your design to be > > some > > > sort of untraditional? I don't think there's any necessity for it > > > > > > a "good design" often would be something like this: > > > > > > $var = 'whatever'; > > > > > > if($var) > > > ...do this > > > else > > > ERROR('no var') // some your func to output the error mess or to > continue > > > with debugging > > > > > > in most cases it will work better and simpler for you without spending > > these > > > bazillions of important for every developer seconds. > > > > > > > > > > > > Sincerely, > > > > > > Maxim Maletsky > > > Founder, Chief Developer > > > > > > PHPBeginner.com (Where PHP Begins) > > > maxim@phpbeginner.com > > > www.phpbeginner.com > > > > > > > > > > > > > > > > > > -----Original Message----- > > > From: Joe Stump [mailto:jstump@zebulon.miester.org] > > > Sent: Friday, February 23, 2001 3:07 AM > > > To: Steve Edberg > > > Cc: Jacky@lilst; php-general@lists.php.net > > > Subject: Re: [PHP] isset() > > > > > > > > > I stand firm on strlen() for the following reasons ... > > > > > > if(!$var) will sometimes act strangely (has for me in the past) when > > > variables > > > are set to something other than what you are expecting. > > > > > > if(isset($var)) will return true if your text field is declared but not > > > filled > > > in. > > > > > > if(empty($var)) will return true if $var is set to 0 (for obvious > reason) > > so > > > is > > > only good for certain instances. > > > > > > strlen() on the other hand converts the variable to a string and returns > a > > > count > > > of characters. It's never failed or acted funky. For this reason I use > it > > > religiously. > > > > > > Others might say "well it's extra overhead" to which I reply > > > "I'll take > an > > > extra > > > bazillionth of a second to know for sure I have what I need" > > > > > > --Joe > > > > > > On Thu, Feb 22, 2001 at 08:18:22AM -0800, Steve Edberg wrote: > > > > I would do this: > > > > > > > > if (!$AgeChild) $AgeChild = 'NA'; > > > > > > > > More compact, easier to read (to me, anyway). This presumes that a > > > > value of '' (empty string, interpreted by PHP as false) is NOT a > > > > valid value here. > > > > > > > > As far as your sniplet goes, it is possible that there may be some > > > > PHP type-casting issues here, depending on: whether $AgeChild is > > > > numeric or string; the fact that the STRING "false" isn't > > > > equivalent > > > > to the CONSTANT false, the use of == vs. ===. > > > > > > > > Time to check out the docs - specifically the types and variables > > > > sections (also the functions->variables section)... > > > > > > > > - steve > > > > > > > > > > > > > > > > At 5:07 PM -0600 2/22/01, Jacky@lilst wrote: > > > > >People > > > > >I tried to check if teh field has set a vaule in it before submit > > > > >using isset with the sniplet below > > > > > > > > > >if ((isset($AgeChild))=="false") { > > > > >$AgeChild = "NA"; > > > > >} > > > > > > > > > >The resule is that it always displays NA whether or not it has vaule > > > > >in the field, what is the correct way of using isset for this > > > > >purpose? Or should I use empty() ? > > > > >Jack > > > > >jacky@activelifestyle.com > > > > >"There is nothing more rewarding than reaching the goal you set for > > > yourself" > > > > > > > > > > > > -- > > > > +--- "They've got a cherry pie there, that'll kill > > ya" ------------------+ > > > > | Steve Edberg University of California, > Davis > > | > > > > | sbedberg@ucdavis.edu Computer > Consultant > > | > > > > | http://aesric.ucdavis.edu/ > http://pgfsun.ucdavis.edu/ > > | > > > > +-------------------------------------- FBI Special Agent Dale > > Cooper ---+ > > > > > > > > -- > > > > 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 Hacker, > > > -o) > > > http://www.miester.org http://www.care2.com > > > /\\ > > > "It's not enough to succeed. Everyone else must fail" -- Larry Ellison > > > _\_V > > > > -------------------------------------------------------------------------- > > -- > > > --- > > > > > > > > > -- > > > 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 Hacker, > > -o) > > http://www.miester.org http://www.care2.com > > /\\ > > "It's not enough to succeed. Everyone else must fail" -- Larry Ellison > > _\_V > > -------------------------------------------------------------------------- > -- > > --- > > > > > > -- > > 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 Hacker, > -o) > http://www.miester.org http://www.care2.com > /\\ > "It's not enough to succeed. Everyone else must fail" -- Larry Ellison > _\_V > -------------------------------------------------------------------------- -- > --- > > > -- > 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 Hacker, -o) http://www.miester.org http://www.care2.com /\\ "It's not enough to succeed. Everyone else must fail" -- Larry Ellison _\_V ---------------------------------------------------------------------------- --- -- 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

« previous php.general (#41490) next »