From: syphon dot and dot the dot trick at gmai dot com
Operating system: Win32 / Linux
PHP version: 5.2.6
PHP Bug Type: Strings related
Bug description: Incorrect addition of float and string
Description:
------------
I've been setting up our system to receive payments via Paypal. Paypal
talks via IPN to a URL that I specify. In my code I have logic to verify
the transaction.
On one line I ran into the problem of addition when verifying transaction
amounts.
I have tried this test on Win32 running PHP 5.2.3 (Basic AppServ install)
and on our live linux environment PHP 5.2.6 with both showing the same
results.
Reproduce code:
---------------
$SubTotal = "67.43";
$Tax = "3.37";
$Amount = $SubTotal + $Tax;
"<div>".var_dump($Amount)."</div>";
$Array = array("mc_gross" => "70.80");
echo ($Amount == $Array['mc_gross']) ? $Array['mc_gross'].' is equal to
'.$Amount : 'These values are not equal. '.$Array['mc_gross']." is not
equal to ".$Amount;
echo '<br /><br />Second Test<br /><br />';
$Amount = 70.8;
"<div>".var_dump($Amount)."</div>";
echo ($Amount == $Array['mc_gross']) ? $Array['mc_gross'].' is equal to
'.$Amount : 'These values are not equal. '.$Array['mc_gross']." is not
equal to ".$Amount;
Expected result:
----------------
The variable mc_gross, a string with a string value "70.80" should equal
the variable $Amount with the float value of 70.8
Actual result:
--------------
The first test adds the two variables ($Subtotal and $Tax) together into
the variable $Amount. Using var_dump php tells us that $Amount is a float
with the value 70.8
When comparing that variable to the one supplied by Paypal (mc_gross) php
says that the values are not equal to each other.
If you redeclare the variable $Amount and with the value 70.8 and try
again, php says the values are equal.
var_dump confirms the variable types and value.
--
Edit bug report at http://bugs.php.net/?id=46537&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=46537&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=46537&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=46537&r=trysnapshot60
Fixed in CVS:
http://bugs.php.net/fix.php?id=46537&r=fixedcvs
Fixed in CVS and need be documented:
http://bugs.php.net/fix.php?id=46537&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=46537&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=46537&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=46537&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=46537&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=46537&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=46537&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=46537&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=46537&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=46537&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=46537&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=46537&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=46537&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=46537&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=46537&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=46537&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=46537&r=mysqlcfg