I am having a problem with an array changing the value of keys on me. In the example I'm providing below it starts out ok, but at some point php is turning my string into an integer and changing that integer when inserting it into another array as a key.
Code
-----------------
$fund = '01';
$division = '1';
$gl_transactions[$fund] = array();
$glint = array($division=>array('gl_cash_account'=>'1800001040000000'));
print chr(10).'1:'.chr(10);
print_r($glint);
$gl = $glint[$division]['gl_cash_account'];
print chr(10).'2:'.chr(10);
print $gl;
$gl_transactions[$fund][$gl]['description'] = 'MTS DISBURSEMENTS';
print chr(10).'3:'.chr(10);
print_r($gl_transactions);
Expected output
---------------
1:Array([1] => Array([gl_cash_account] => 1800001040000000 ))
2:1800001040000000
3:Array([01] => Array([1800001040000000] => Array([description] => MTS DISBURSEMENTS)))
Actual output
---------------
1:Array([1] => Array([gl_cash_account] => 1800001040000000 ))
2:1800001040000000
3:Array([01] => Array([1721082880] => Array([description] => MTS DISBURSEMENTS)))
notice the index changed from 1800001040000000 to 1721082880
Obsticles
These big numbers are G/L Account numbers and cannot be changed to smaller numbers. We have tens of thousands of pieces of code, over a million lines of code in our product and cannot go through every bit of it to find where this may be an issue and rewrite it. This is just a generic example of something that we do in many places, building multidimensional arrays using data from a database. I can simply cast the variable as a string when inserting into the array to fix the above example, but backfilling 1M+ lines of code is not a viable option.
On my development machine I run php 5.3 MSSQL, Windows, and IIS. I do not get this error with the above code but I do get it when simply setting a variable as an integer and then inserting it into an array as a key. i.e. $gl = 1800001040000000; $ar[$gl] = 1; print_r($ar); Now we don't cast a variables to integers in our software, but in the first example php converts it on it's own at some point when it's building the last array when ran on some of our clients systems.
So my questions are:
- What is the exact limit of a numeric array key.
- Is there a way to increase this.
- Has this been fixed or increased in later versions of php beyond 5.2
Other notes
Our software works with several databases, several browsers, window and linux, apache and IIS. We have hundreds of customers using the software all with their own unique setup. Most of our customers are on php 5.2 currently and upgrading them is not possible at this point because of deprecated functions used in our software.