Unpredictable integer overflow with ksort

After making a fix to my PHP application on my test server, I pushed it to my production server and the fix didn't work. After tracking it down I found that ksort() was causing index keys to overflow for integers larger than the max 32-bit signed value (2147483648) on my production server only. On my test server it would only overflow for integers larger than the max signed 64-bit integer (9223372036854775808).

Both servers (as fully as I can tell) have the same software configuration

  • Ubuntu 12.10
  • Kernel version: Linux version 3.0.0-15-generic-pae
  • PHP 5.4.6-1ubuntu1.2

    1. CPU on production: AMD Phenom(tm) II X4 910
    2. CPU on test server: AMD Athlon(tm) II X4 620

To reproduce this issue

$arr = array(2147483648 => 1, 5 => 2); ksort($arr); print_r($arr);

Outputs the following on my production server:

    [-2147483648] => 1
    [5] => 2

The exact same code outputs the following on my test server:

    [5] => 2
    [2147483648] => 1

I'm trying to figure out what could be causing this. Where should I be looking to narrow down why the servers have different integer sizes. Is it possible that I may have a different version of PHP (even though both appear to be the same) that was compiled with 32bit integers?


take a look at PHP_INT_SIZE


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.

I would also suggest to increase PHP memory_limit in php.ini or with ini_set().

Need Your Help

Objective-C accessing properties inside block

objective-c ios objective-c-blocks

I have read Apple's Blocks Programming Topics and my due diligence searching online, but I am still unclear if I am implementing my blocks correctly. I have an array of clients as a property that is

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.