Re: Bug #1088: occasional failure of bitwise &

From: Date: Thu, 01 Jan 1970 00:00:00 +0000
Subject: Re: Bug #1088: occasional failure of bitwise &
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-3677@lists.php.net to get a copy of this message
> if (!$z) { $z = 0; } > if (($z != 1) && ($z != 2) && ($z != 4) && ($z != 8) && ($z != > 16) && > ($z !=32)) { $z = 0; } > if ($z == ($z & $thiscookie)) { $z = 0; } > $thiscookie += $z; > > Tracing the value of $z through the above results in strange errors on the third line, where > the following has occurred: > (a) $z=4, $thiscookie=59, if statement evaluated true and reset $z to 0. > (b) $z=1, $thiscookie=58, if statement evaluated true and reset $z to 0. Hrm.. A couple of things. That second check is insane. You could do the same thing with a simple: if(!($z & 63)) { $z = 0; } As for the strangeness. Probably because these things are not integers coming in. Before all this, add these two lines: $z = (int)$z; $thiscookie = (int)$thiscookie; -Rasmus -- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net For help: php-dev-help@lists.php.net

« previous php.dev (#3677) next »