Jump to content

PHP Interger Overflow Handling Help


davlee

Recommended Posts

I'm having problems running a php program on my Linux box which runs fine on my Windows box.

 

I traced the problem down to a line of code:

 

$higherValue = 0xFFFFFFFF;

 

This should be an maximum unsigned int value of 4294967295, but PHP doesn't handle unsigned int so it should convert it to a float. This is not happening on my system. Instead it is just converting it to a max int value of 2147483647.

 

I wrote a small php test script:

 

var_dump(0x00000000);
var_dump(0xFFFFFFFF);
var_dump(0xFFFFFFFE);
 
On Windows:
 
int(0)
float(4294967295)
float(4294967294)
 
On Linux:
 
int(0)
int(2147483647)
int(2147483647)
 

Versions:

 

Windows:

 

>.\win32\php -c php-win.ini -v
PHP 5.3.15 (cli) (built: Jul 20 2012 00:20:38)
Copyright © 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright © 1998-2012 Zend Technologies
 

Linux:

> php -v

PHP 5.3.27 (cli) (built: Jun 24 2014 01:48:44)
Copyright © 1997-2013 The PHP Group
Zend Engine v2.3.0, Copyright © 1998-2013 Zend Technologies
 
 
How do I get integer overflow working? Do I have a bad build of PHP?
Link to comment
Share on other sites

In your Linux Box what echo PHP_INT_MAX produce?

 

from the manual

The size of an integer is platform-dependent, although a maximum value of about two billion is the usual value (that's 32 bits signed). 64-bit platforms usually have a maximum value of about 9E18, except for Windows, which is always 32 bit. PHP does not support unsigned integers. Integer size can be determined using the constant PHP_INT_SIZE, and maximum value using the constant PHP_INT_MAX since PHP 4.4.0 and PHP 5.0.5.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.