Page 1 of 1

Bitwise Comparison

Posted: Thu Jun 28, 2007 10:48 am
by Benjamin
Be careful, on several systems I have tested, in php 5, some, but not all valid bitwise comparisons will return false if they are not type casted to integers. I had a few failing coming out of a database.

Code: Select all

if (2 & 5622)
{
    echo "ok<br>";
} else {
    echo "failed<br>";
}

if ((string) 2 & (string) 5622)
{
    echo "ok<br>";
} else {
    echo "failed<br>";
}