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 #177468 is a reply to message #177467] Sat, 31 March 2012 15:27 Go to previous messageGo to previous message
Shelly[1] is currently offline  Shelly[1]
Messages: 16
Registered: March 2012
Karma:
Junior Member
On 3/31/2012 10:05 AM, Jerry Stuckle wrote:
> On 3/30/2012 4:55 PM, Shelly wrote:
>> On 3/30/2012 4:30 PM, Thomas Mlynarczyk wrote:
>>> Shelly schrieb:
>>>
>>>> $val = TRUE;
>>>
>>>> $val &= TRUE;
>>>>
>>>> which is identical to
>>>>
>>>> $val = $val && TRUE;
>>>
>>> No. &= is a bitwise operator while && means the logical AND operator. So
>>> when you do $val &= TRUE, PHP is trying to do TRUE & TRUE, but since
>>> bitwise operators only work with integers, TRUE is first coerced into
>>> the integer 1. So the operation ends up as 1 & 1 yielding the integer 1.
>>> Thus, $val = 1. The === operator checks the type of the operands which
>>> are int and bool and thus not the same, while == tries to convert the
>>> operands into something "comparable" and since they are both "truish"
>>> the result is TRUE here.
>>>
>>> Greetings,
>>> Thomas
>>>
>>
>> Thank you. That makes a lot of sense. So, what I have to do if I want to
>> use === is to use the expanded form
>>
>> $val = $val && TRUE;
>>
>> Right?
>>
>>
>
> I should also add that you need to be careful and use the correct
> operator. For instance, 2 & TRUE is false, while 2 && TRUE is true.
>

Thanks. All my validation routines return either TRUE or FALSe. I have
a flag that repetitively goes something like this after initializing
$theFlag to TRUE:

$theFlag = $theFlag && validation_routine_call(arguments);

for each of the many validation routines.

At the end I do something if $theFlag === TRUE, and don't if not.

What I had been doing, incorrectly, (which led me to start this thread) was:

$theFlag &= validation_routine_call(arguments);

--
Shelly
[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: Fri Nov 22 20:57:35 GMT 2024

Total time taken to generate the page: 0.04681 seconds