RE: [PHP] Alternate Colors in Rows ($r=!$r)

This is a discussion on RE: [PHP] Alternate Colors in Rows ($r=!$r) within the PHP General forums, part of the PHP Programming Forums category; [snip] The value of the expression is the value assigned. Since the ! operator will always return a boolean then the ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-05-2007
Jay Blanchard
 
Posts: n/a
Default RE: [PHP] Alternate Colors in Rows ($r=!$r)

[snip]
The value of the expression is the value assigned. Since the ! operator
will always return a boolean then the assigned value is going to be a
boolean. So $r will always contain a boolean for the purposes of the
ternary operation.
[/snip]

And it also work if the statement is not ternary
Reply With Quote
  #2 (permalink)  
Old 10-05-2007
Jay Blanchard
 
Posts: n/a
Default RE: [PHP] Alternate Colors in Rows ($r=!$r)

[snip]
The value of the expression is the value assigned. Since the ! operator
will always return a boolean then the assigned value is going to be a
boolean. So $r will always contain a boolean for the purposes of the
ternary operation.

And it also work if the statement is not ternary
[/snip]

And now for a little clarity. THIS is not a ternary

if($r = !$r)

it is a conditional test.

? foo : bar;

....is the ternary operation. Just wanted to clean up the usage there.
Reply With Quote
  #3 (permalink)  
Old 10-05-2007
Jay Blanchard
 
Posts: n/a
Default RE: [PHP] Alternate Colors in Rows ($r=!$r)

[snip]
if($r = !$r)
[/snip]

And I hit send before I finished my thought process oh my goodness isn't
it five o'clock yet and why do all of these people keep coming by my
office distracting me from getting something useful done like replying
the PHP list and why doesn't someone bring me a beer?

if($r = !$r) is a conditional check that most folks would read as
follows;

if the assignment of $r to !$r occurs the statement is TRUE. Since PHP
is loosely typed we all know that an assignment will occur regardless of
what is assigned. That why we use additional operators to determine the
TRUEness of a statement;

if($r == !$r) or if($r === !$r)

That is why we code conditional checks (if we're smart) by putting the
constant on the left hand side of the check to reduce/locate
typographical errors when coding conditional checks; if(1 == $foo),
because if we assign $foo to 1 the compiler will throw an error and we
can fix it pretty quickly.

This is one of those special cases where this logic gets thrown out. I
am going to see if the same thing will work in C++ because I am pretty
sure that no other language has this feature....maybe C.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:26 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0