Re: Alternate Colors in Rows ($r=!$r)
| From: | Robert Cummings | Date: | Fri, 05 Oct 2007 18:55:22 +0000 |
| Subject: | Re: Alternate Colors in Rows ($r=!$r) | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-262839@lists.php.net to get a copy of this message | ||
On Fri, 2007-10-05 at 14:49 -0400, Nathan Nobbe wrote:
> On 10/5/07, Jay Blanchard <jblanchard@pocket.com> wrote:
>
> It looks like PHP has an "unintentional feature". Doing this;
> if($r =
> !$r) should always return TRUE because it is an assignment. I
> don't know
> if I would rely on this.
>
>
>
> its not an unintentional operation; its the order of operations.
> logical !
> and the ternary ? :
> takes precedence over the assignment statement
> =
>
> http://us.php.net/manual/en/language.operators.php
>
> personally, i wont argue w/ the compact nature of the statement; its
> nice.
> its mysterious statements like this that make code fragile, imho.
> i prefer the modulus approach.
Actually the code used wrapped the assignment in parenthesis to ensure
the assignment occurred before the ternary operator. His code is
elegant, and very clear.
Cheers,
Rob.
--
...........................................................
SwarmBuy.com - http://www.swarmbuy.com
Leveraging the buying power of the masses!
...........................................................