And-equals doesnt retain boolean property, what will?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
McManCSU
Forum Newbie
Posts: 22
Joined: Mon Apr 23, 2007 6:30 pm

And-equals doesnt retain boolean property, what will?

Post by McManCSU »

This is sort of in another post, but since it has somewhat become cluttered, I am starting this new one:

I noticed that an "&=" or "|=" on a Boolean value will not retain its Boolean type. For example if I do something like this:

Code: Select all

$a = false;
$b = false;
$a &= $b;

if ($a === false)
{
    // This will not pass
}
Question: Is there a more efficient way to do this besides doing something longer such as:

Code: Select all

$a = $a && $b;
Thanks!

I think I gave a little better example in my other post (middle or so): viewtopic.php?p=379808#379808
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Yeah, it's a bitwise operator and PHP is converting the booleans to integers before the operation, and returning an integer. $a = $a && $b is your best bet.
Post Reply