03-14-2008, 01:23 AM
|
#4 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 714
Thanks: 2
|
What you're doing there is utilizing the bitwise 'xor' operator. It's a little bit in depth to explain this operation in detail so we'll go with "it just works"... sort of. Since we're only working with one bit (0 or 1) the expression works something like:
PHP Code:
$myVar = FALSE; // (bool) false
$myVar ^= TRUE; // (int) 1
$myVar ^= TRUE; // (int) 0
$myVar ^= TRUE; // (int) 1
So, really we're making FALSE into (int) 1, or TRUE into (int) 0 rather than strictly converting between TRUE/FALSE. An alternative (which actually preserves boolean type) would be to go along the lines of:
PHP Code:
$myVar = FALSE; // (bool) false
$myVar = !$myVar; // (bool) true
$myVar = !$myVar; // (bool) false
$myVar = !$myVar; // (bool) true
As mentioned above, it keeps the boolean type rather than giving integer results and is also, for me at least, more logical (pardon the pun) in that we're saying (if $myVar is originally true) "$myVar equals not $myVar" => "$myVar equals not true" => "$myVar equals false".
__________________
|
|
|
|