Re: Assigns True but not false?

From: Date: Wed, 07 Dec 2005 01:26:34 +0000
Subject: Re: Assigns True but not false?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-227004@lists.php.net to get a copy of this message
On Tue, Dec 06, 2005 at 12:38:28PM -0500, Gabe wrote: > In this if statement, if the condition is true, then it will assign true > to the array (as I want it to). If the condition evaluates to false, it > assigns nothing. Any idea why it won't assign false? If I switch the > FALSE boolean value to the number 0, that will get assigned. Seems > kinda strange... > > $this->m_arrQuesInfo[$this->m_itemID]['blnVacPromo'] = ( ( > !empty($_POST['vac_promo']) ) && ( $_POST['vac_promo'] == > 'on' ) ) ? > TRUE : FALSE; It only appears to be nothing, if you issue: php -r "echo false;" Nothing happens. if you issue: php -r "var_dump(false);" You'll get bool(false) Btw, your condition is doing extra work. Consider the output of: php -r "var_dump(0 && 1);" Outputs: bool(false) So your condition to return true or false isn't really needed, a simple: $this->m_arrQuesInfo[$this->m_itemID]['blnVacPromo'] = ( !empty($_POST['vac_promo']) && $_POST['vac_promo'] == 'on'; ) Will be exactly the same thing. Also I would suggest changing empty() to isset(), so you would have $this->m_arrQuesInfo[$this->m_itemID]['blnVacPromo'] = ( isset($_POST['vac_promo']) && $_POST['vac_promo'] == 'on'; ) empty() in this case doesn't really mean anything, the isset() will prevent a E_NOTICE to happen. HTH, Curt. -- cat .signature: No such file or directory

« previous php.general (#227004) next »