Re: Boolean type forced on string assignment inside if statement

From: Date: Thu, 03 Jan 2013 15:26:39 +0000
Subject: Re: Boolean type forced on string assignment inside if statement
References: 1 2 3 4 5 6  Groups: php.general 
Request: Send a blank email to php-general+get-320003@lists.php.net to get a copy of this message
On 1/2/2013 2:02 PM, Marc Guay wrote:
Something else that's happening with this, which makes it a Bad Idea (tm) is that when the operator is "or", as it is in my real life scenerio, the 2nd variable occasionally doesn't get populated if the first one returns true. if ($a = "foo" || $b = "bar"){
     echo $a."<br />".$b;
} Returns foo And even worse, because I have this in a loop, what can happen is that if $b gets populated on one loop, it doesn't get reset for the next one so the data gets seriously bungled. Moral of the story: Don't be so fancy on your first day back after vacation. :) Marc You actually use statements like that in order to populate vars? Whatever happened to "simple to understand, easy to maintain" coding practices?
The only time I use a single '=' symbol in an if statement is when I forget to use two of them! Must be my old school, old languages habits but this style of programming reminds me of the days when we used to pack empty spaces in assembler code with constants or byte-size vars in order to save memory back when memory was the most precious resource one had.

« previous php.general (#320003) next »