|  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
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-2023 The PHP Group
All rights reserved.
Last updated: Tue Oct 03 07:01:24 2023 UTC