ID: 47716
Comment by: codeslinger at compsalot dot com
Reported By: codeslinger at compsalot dot com
Status: Open
Bug Type: Scripting Engine problem
Operating System: windows 2000
PHP Version: 5.2.9
New Comment:
in case it wasn't clear from the description above, this is using the
CLI version of php.
also unlike a number of other bugs that I have read. Adding and
removing various lines of code -- which I did quite a bit of while
isolating this problem, plus adding a planned revision to the code --
had no effect on the result, the bug was totally repeatable.
This was using the official php windows binary, not one that I
compiled. The only difference between the working and not working
versions of the program are the php version.
How is it possible to convert a string to a float and have the result
contain a colon character???
Previous Comments:
------------------------------------------------------------------------
[2009-03-19 12:11:23] codeslinger at compsalot dot com
Description:
------------
It is with great hesitancy that I enter this bug, because I am not able
to produce a simple test case for it. But the bug is very serious.
I have a program that calculates and sends out customer statements.
Without making any changes to the php program itself which has been
running fine, I upgraded to PHP 5.2.9 and also tested with 5.2.9-1
both with and without xdebug enabled.
The math is bad, the calculations are incorrect. Below is a program
that displays this problem, but it does not fail when run stand-alone,
this program only fails when run inside of the billing program's context
where it is calculating the statement balances.
The billing program of course does a billion things before it gets to
this point. But at that point the math behavior of PHP is corrupt.
Wrong math results are the only visible sign of the problem, the program
runs to completion and prints the statements etc.
The program reads the numbers from a database as strings and converts
them to floats to do the totals. This is not a case of loss of
precision, as I said the program runs fine on 5.2.5. But sprintf will
convert "19.000000" to = 18:0
Note the colon, I'm using the default language settings of USA
English.
Probably related to Bug #47304
Reproduce code:
---------------
<?php
//I ran a series of tests all of them failed,
//it was totally consistent and reproducible.
//Here are the most interesting tests/results.
$arrMsgs = array();
//for the sake of completeness, I also added this,
//it made no difference
$arrMsgs[] = "Locale = ".setlocale(LC_ALL, "english-usa");
$arrMsgs[] = "memory_get_peak_usage(true) = ".
memory_get_peak_usage(true);
$arrMsgs[] = "memory_get_peak_usage(false) = ".
memory_get_peak_usage(false);
$arrMsgs[] = "memory_get_usage(true) = ". memory_get_usage(true);
$arrMsgs[] = "memory_get_usage(false) = ". memory_get_usage(false);
$arrMsgs[] = "(float)19.000000 = ".(float)19.000000;
$arrMsgs[] = "(float)'19.000000' = ".(float)'19.000000';
$arrMsgs[] = "round('19.000000', 2) = ".round('19.000000', 2);
print_r($arrMsgs);
?>
Expected result:
----------------
when I run this program on PHP 5.2.5 I get the following result
[DebugInfo] => Array
(
[0] => memory_get_peak_usage(true) = 3932160
[1] => memory_get_peak_usage(false) = 3731872
[2] => memory_get_usage(true) = 3932160
[3] => memory_get_usage(false) = 3589320
[10] => (float)19.000000 = 19
[11] => (float)'19.000000' = 19
[12] => round('19.000000', 2) = 19
)
Actual result:
--------------
[DebugInfo] => Array
(
[0] => memory_get_peak_usage(true) = 3932160
[1] => memory_get_peak_usage(false) = 3732128
[2] => memory_get_usage(true) = 3932160
[3] => memory_get_usage(false) = 3589216
[10] => (float)19.000000 = 18.:
[11] => (float)'19.000000' = 18.:
[12] => round('19.000000', 2) = 18.:
)
notice the colons following the numbers, I did not add those, it is
part of the failure.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=47716&edit=1