php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #10288 weird intval() and settype('integer') behaviour: loosing bits?
Submitted: 2001-04-11 09:33 UTC Modified: 2001-06-01 16:53 UTC
From: vk at mac dot dhs dot org Assigned:
Status: Closed Package: Math related
PHP Version: 4.0.4pl1 OS: linux rh6.2
Private report: No CVE-ID: None
 [2001-04-11 09:33 UTC] vk at mac dot dhs dot org
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



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-06-01 16:53 UTC] sniper@php.net
I can't reproduce this with PHP 4.0.6RC1.
Please try it: 

http://www.php.net/~andi/php-4.0.6RC1.tar.gz

--Jani

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 11:01:30 2024 UTC