Bug #54973 [Ana->Csd]: SimpleXML casts intergers wrong.
Edit report at https://bugs.php.net/bug.php?id=54973&edit=1
ID: 54973
Updated by: nikic@php.net
Reported by: bphelpsen at gmail dot com
Summary: SimpleXML casts intergers wrong.
-Status: Analyzed
+Status: Closed
Type: Bug
Package: SimpleXML related
Operating System: Linux
PHP Version: 5.3.6
-Assigned To:
+Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
Fixed by https://github.com/php/php-src/commit/b2b2b437af5495dcb2016be6e45567ed826cb87e
in master.
Previous Comments:
------------------------------------------------------------------------
[2016-09-19 13:30:42] cmb@php.net
Related To: Bug #73108
------------------------------------------------------------------------
[2016-09-19 13:23:44] cmb@php.net
> This shows that the standard class is correctly juggled from a
> string to a float when added to an integer.
Not really. Actually, the object isn't juggled at all, but rather
one of its properties.
------------------------------------------------------------------------
[2013-11-06 14:42:23] corry at jhstudios dot com
$stdobj= new stdClass;
$stdobj->Price='.53';
echo 1+$stdobj->Price;
output:
object(stdClass)#1 (1) { ["Price"]=> string(3) ".53" }
1.53
This shows that the standard class is correctly juggled from a string to a float when added to an
integer. This is in contrast to other comments that suggested that the reported behavior is to be
expected.
------------------------------------------------------------------------
[2013-07-22 08:33:16] kaplan@php.net
The referenced pull request (#213) has two tests to verify the fix for this bug
(when and if ready). Please don't forget to use them when commiting the fix.
------------------------------------------------------------------------
[2011-06-03 11:55:06] cataphract@php.net
I remember seeing this before. The problem is that the Zend engine, when doing the add operation,
converts any objects it finds to ints. The simplexml extension is merely doing what it's asked,
i.e., convert the value of the object to int.
The solution must be either
a) making the Zend Engine default the conversion to a double
b) making the Zend Engine try both a double and an int and compare the two results
c) making the Zend Engine convert the object to a string instead and then convert the string using
the usual means (that is, is_numeric_string)
d) change the API so that cast_object can be told to convert the object to either an int or a
double, sort of like is_numeric_string
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=54973
--
Edit this bug report at https://bugs.php.net/bug.php?id=54973&edit=1
Thread (10 messages)