FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » A little tip
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: A little tip [message #177449 is a reply to message #177447] Fri, 30 March 2012 20:19 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 3/30/2012 2:18 PM, Shelly wrote:
> On 3/30/2012 1:20 PM, Jerry Stuckle wrote:
>> On 3/30/2012 1:02 PM, Shelly wrote:
>>> Here is something I jist came across, so I am passing it on:
>>> ==========
>>> $val= TRUE;
>>> $val &= TRUE;
>>> print ($val === TRUE) ? "Triple is true\n" : "Triple is false\n";
>>> print ($val == TRUE) ? "Double is true\n" : "Double is false\n";
>>>
>>> Results in:
>>> Triple is false
>>> Double is true
>>> ==========
>>>
>>> Who designed that? It is totally counter-intuitive.
>>>
>>
>> Yes, just another problem with PHP. After the second assignment, $val is
>> actually a reference to TRUE. However, a variable should not be able to
>> reference a constant. For instance, what would the following do?
>>
>> $val &= TRUE;
>> $val = 3;
>>
>> Are we setting TRUE to 3 (that's what a reference should do, after all).
>>
>> This is why other languages don't allow references to constants.
>
> Huh? How is it a reference? I wrote
>
> $val = TRUE;
>
> That sets TRUE as the value contained in the location specified by the
> variable $val.
>
> Then I wrote
>
> $val &= TRUE;
>
> which is identical to
>
> $val = $val && TRUE;
>
> isn't it, which should put into the location of $val the resulting value
> of the logical operation of TRUE AND TRUE -- which SHOULD be TRUE.
> Instead, it is something other than FALSE or ZERO, but not === to TRUE.
>
> Your answer seems to be as if I had written
>
> $val = &TRUE;
> $val = 3;
>
> Am I missing something here?
>

You're right, Shelly - it's AND instead of reference. I was mixing it
up with $val = &TRUE.

But this is a bitwise AND - which means the TRUE will be converted to an
integer 1 and the result will be an integer 1. It is non-zero, so it is
TRUE, but it is not a logical TRUE.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: session variable doesn't appear in side bar
Next Topic: Doubt regarding an array of references...
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 23 02:33:59 GMT 2024

Total time taken to generate the page: 0.08066 seconds