Bug #10288: weird intval() and settype('integer') behaviour: loosing bits?

From: Date: Wed, 11 Apr 2001 13:33:41 +0000
Subject: Bug #10288: weird intval() and settype('integer') behaviour: loosing bits?
Groups: php.dev 
Request: Send a blank email to php-dev+get-51442@lists.php.net to get a copy of this message
From: vk@mac.dhs.org Operating system: linux rh6.2 PHP version: 4.0.4pl1 PHP Bug Type: *General Issues Bug description: weird intval() and settype('integer') behaviour: loosing bits? hello, take a look at this script: ----->8-------->8-------->8-------->8-------->8--- // these are min and max signed 32bits integers $x = -2147483648; // 0x80000000 $y = 2147483647; // 0x7FFFFFFF echo 'x = '.$x.'<br>'; echo 'y = '.$y.'<br>'; if($x > $y) echo 'x > y'; else echo 'x <= y'; echo '<br>'; $x = intval($x); echo 'x = intval(x)<br>'; $y = intval($y); echo 'y = intval(y)<br>'; echo 'x = '.$x.'<br>'; echo 'y = '.$y.'<br>'; if($x > $y) echo 'x > y'; else echo 'x <= y'; echo '<br>'; ----->8-------->8-------->8-------->8-------->8--- it displays this in php3* and 4*: x = -2147483648 y = 2147483647 x <= y x = intval(x) y = intval(y) x = -2147483648 y = 2147483647 x > y the same thing will happen if intval(var) is replaced by settype(var, 'integer') thanks -- vedad -- Edit Bug report at: http://bugs.php.net/?id=10288&edit=1

« previous php.dev (#51442) next »