Re: Bitwise operation giving wrong results

From: Date: Thu, 30 Oct 2008 07:42:28 +0000
Subject: Re: Bitwise operation giving wrong results
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-282614@lists.php.net to get a copy of this message
Usually in PHP one does not take much care about the data types, but in this case you absoloodle have to. If you use bit operators on a character then its ascii number will be taken instead (how should a number based operation work with a string?) also if you pass on $_GET params directly into ay bitwise operation you might get some un-nice behaviour. So check them first. <?php $a = $b = false; if (is_numeric($_GET['b'].$_GET['a'])) { $a = (int)$_GET['a']; $b = (int)$_GET['b']; echo $a & $b; } ?>

« previous php.general (#282614) next »