RE: [PHP] isset()

From: Date: Sat, 24 Feb 2001 06:15:59 +0000
Subject: RE: [PHP] isset()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-41441@lists.php.net to get a copy of this message
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

« previous php.general (#41441) next »