From:             codeslinger at compsalot dot com
Operating system: windows 2000
PHP version:      5.2.9
PHP Bug Type:     Scripting Engine problem
Bug description:  Invalid/Corrupt Math Convert string to float

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 bug report at http://bugs.php.net/?id=47716&edit=1
-- 
Try a CVS snapshot (PHP 5.2):        
http://bugs.php.net/fix.php?id=47716&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):        
http://bugs.php.net/fix.php?id=47716&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):        
http://bugs.php.net/fix.php?id=47716&r=trysnapshot60
Fixed in CVS:                        
http://bugs.php.net/fix.php?id=47716&r=fixedcvs
Fixed in CVS and need be documented: 
http://bugs.php.net/fix.php?id=47716&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=47716&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=47716&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=47716&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=47716&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=47716&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=47716&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=47716&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=47716&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=47716&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=47716&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=47716&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=47716&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=47716&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=47716&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=47716&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=47716&r=mysqlcfg

Reply via email to