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
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
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
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

Add a Patch

Pull Requests

Add a Pull Request

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-2021 The PHP Group
All rights reserved.
Last updated: Wed Dec 01 04:03:40 2021 UTC