Page 1 of 1

And-equals doesnt retain boolean property, what will?

Posted: Wed May 09, 2007 10:56 am
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

Posted: Wed May 09, 2007 11:05 am
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.