|  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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: vk at mac dot dhs dot org
New email:
PHP Version: OS:


 [2001-04-11 09:33 UTC] vk at mac dot dhs dot org

take a look at this script:


// 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';
   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';
   echo 'x <= y';
echo '<br>';


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')

-- vedad


Add a Patch

Pull Requests

Add a Pull Request


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


PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jul 20 00:01:03 2024 UTC