ID: 42780
Updated by: [EMAIL PROTECTED]
Reported By: lordi at msdi dot ca
-Status: Assigned
+Status: Wont fix
Bug Type: SimpleXML related
Operating System: Freebsd + windows
PHP Version: 5.2.4
Assigned To: rrichards
New Comment:
The behavior is defined by the engine not the extension. When
performing mathematical operations on objects, they are treated as
integers. It is up to the user to cast the object to the appropriate
type to maintain proper precision.
Previous Comments:
------------------------------------------------------------------------
[2007-09-27 16:51:25] lordi at msdi dot ca
Description:
------------
Calculations on values got from a simplexml object dont work as
expected.
String values looking as float seems to be casted as integers
Reproduce code:
---------------
<?php
$objXML = new SimpleXMLElement('<test x="-123.45"></test>');
//Shows correctly
echo $objXML['x']."\n";
//We loose the decimals
echo $objXML['x'] + $objXML['x']."\n";
//This works if we cast the amounts
echo (float)$objXML['x'] + (float)$objXML['x']."\n";
//Calculated on a string, no problem
echo "-123.45" + "-123.45";
?>
Expected result:
----------------
-123.45
-246.9
-246.9
-246.9
Actual result:
--------------
-123.45
-246
-246.9
-246.9
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=42780&edit=1