Bug #54973 [NEW]: SimpleXML casts intergers wrong.

From: Date: Wed, 01 Jun 2011 20:18:28 +0000
Subject: Bug #54973 [NEW]: SimpleXML casts intergers wrong.
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-161115@lists.php.net to get a copy of this message
From:             
Operating system: Linux
PHP version:      5.3.6
Package:          SimpleXML related
Bug Type:         Bug
Bug description:SimpleXML casts intergers wrong.

Description:
------------
When an XML node value is an integer SimpleXML always casts it to an int,
even if its a float or double.

Test script:
---------------
<?php
$xml =
simplexml_load_string("<xml><number>214748364800</number></xml>");

echo $xml->number . "\n"; // the proper number

$int = $xml->number / 1024 / 1024 / 1024; // initial cast to an int causes
problems
echo $int . "\n"; 

$double = (double) $xml->number / 1024 / 1024 / 1024; // hard cast to a
double fixes it
echo $double . "\n";
?>

Expected result:
----------------
214748364800
200
200

Actual result:
--------------
214748364800
1.9999999990687
200

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



Thread (10 messages)

« previous php.bugs (#161115) next »