Re: Boolean type forced on string assignment inside if statement

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux