Re: reason for a "Notice:.." on one site but not another? (Same code.)

From: Date: Mon, 10 Aug 2009 18:27:21 +0000
Subject: Re: reason for a "Notice:.." on one site but not another? (Same code.)
References: 1 2 3 4 5 6 7 8  Groups: php.general 
Request: Send a blank email to php-general+get-296560@lists.php.net to get a copy of this message
If you switch it around you'll get a notice because the IF evaluates from left to right. So you just want to make sure you check isset() first. This would throw a notice: if($_POST['UserWishesDateRange'] == 'T' && isset($_POST['UserWishesDateRange'])) {
Aha! That must be what I tried and was still getting the notice! Interesting that it works (without notice) if we check against the isset () one first. It makes if() look more intelligent that I would think... as if it saying, "good now that we've established that the var isset, now is it also equal to '___'., as opposed to just, "is var set, and is var equal to "___'.
this is not "intelligence" its just pure math. the '&&' says if BOTH expressions are true then the whole expression is true. so if the first one is false, the whole is false, why checking the next one in the underlaying C it would be something like this { if ( expression == false ) return false; if ( expression == false) return false; return true; }
I would have thought both would have to be true on their own (without notice) in order for the the combined expression to be true (without notice). But Shawn pointed out that the order matters; if we check for the var's value before checking if it isset then we get a notice, but if the order is reversed, then we get no notice.

« previous php.general (#296560) next »