ID: 25425
User updated by: crescent at corruptinteractive dot com
Reported By: crescent at corruptinteractive dot com
Status: Open
Bug Type: Arrays related
Operating System: FreedBSD
PHP Version: 4.3.3
New Comment:
Temporary fix - cast the array elements of float type to a string
before serialize().
Use settype($array, "string")
Previous Comments:
------------------------------------------------------------------------
[2003-09-08 02:24:15] crescent at corruptinteractive dot com
Description:
------------
This bug only appeared after upgrading from php 4.3.1 to php 4.3.3
When serializing an array of floating point values with a specific
decimal value of significance (ie: thousandths), once the array is
serialized, bogus values are stored after the hundredth decimal
position.
Here is a short, simple example:
Reproduce code:
---------------
$array[0] = 0;
$array[1] = 1.111;
$array[2] = 2.222;
$array[3] = 3.333;
$array[4] = 4.444;
$array[5] = 5.555;
$array = serialize($array);
echo "Array = $array";
Expected result:
----------------
Array =
a:6:{i:0;i:0;i:1;d:1.111;i:2;d:2.222;i:3;d:3.333;i:4;d:4.444;i:5;d:5.555;}
Actual result:
--------------
Array =
a:6:{i:0;i:0;i:1;d:1.1109999999999999875655021241982467472553253173828125;i:2;d:2.221999999999999975131004248396493494510650634765625;i:3;d:3.3330000000000001847411112976260483264923095703125;i:4;d:4.44399999999999995026200849679298698902130126953125;i:5;d:5.55499999999999971578290569595992565155029296875;}
Notice the bogus values after the hundredth decimal place for each
array element.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=25425&edit=1