#31366 [NEW]: Weird bug with setlocale and serialize
| From: | info at smartlogic dot nl | Date: | Fri, 31 Dec 2004 10:41:47 +0000 |
| Subject: | #31366 [NEW]: Weird bug with setlocale and serialize | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-71348@lists.php.net to get a copy of this message | ||
From: info at smartlogic dot nl
Operating system: Linux
PHP version: 4.3.10
PHP Bug Type: Math related
Bug description: Weird bug with setlocale and serialize
Description:
------------
After setting the setlocale the decimal point disappears.
This is the same bug as "Bug #14235: serialize and setlocale: inconsistent
behavior" but it still appears in PHP 4.3.10 while the possible solution
indicates:
"This bug has already been fixed in the latest released version of
PHP, which you can download at http://www.php.net/downloads.php
this was fixed in 4.1.x with the switch to a non-sprintf-based serialize
implementation."
Reproduce code:
---------------
#code without setlocale
echo "* WITHOUT setlocale\n\n";
bug_test();
#code with setlocale
echo "* WITH setlocale\n\n";
setlocale (LC_ALL, 'nl_NL');
bug_test();
function bug_test()
{
$bill_lines[0]["price"]=42.02;
echo "Original Input:
".$bill_lines[0]["price"]."\n\nArray:\n\n";
print_r(array_values($bill_lines));
$encoded=serialize($bill_lines);
echo "\n\nSerialized array: $encoded \n\n";
$decoded=unserialize($encoded);
echo "Ouput after unserialize: ".$decoded[0]["price"]."\n\n";
}
Expected result:
----------------
The output after the setlocale and the unserialize is 42 instead of 42,02
or 42.02
Actual result:
--------------
* WITHOUT setlocal
Original Input: 42.02
Array:
Array
(
[0] => Array
(
[price] => 42.02
)
)
Serialized array:
a:1:{i:0;a:1:{s:5:"price";d:42.02000000000000312638803734444081783294677734375;}}
Ouput after unserialize: 42.02
* WITH setlocale
Original Input: 42,02
Array:
Array
(
[0] => Array
(
[price] => 42,02
)
)
Serialized array:
a:1:{i:0;a:1:{s:5:"price";d:42.02000000000000312638803734444081783294677734375;}}
Ouput after unserialize: 42
--
Edit bug report at http://bugs.php.net/?id=31366&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=31366&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=31366&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=31366&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=31366&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=31366&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=31366&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=31366&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=31366&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=31366&r=support
Expected behavior: http://bugs.php.net/fix.php?id=31366&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=31366&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=31366&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=31366&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=31366&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=31366&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=31366&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=31366&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=31366&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=31366&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=31366&r=mysqlcfg