php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61877 Array key not casted to Integer.
Submitted: 2012-04-30 02:23 UTC Modified: 2012-04-30 20:57 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: fred dot stcm at gmail dot com Assigned:
Status: Open Package: SimpleXML related
PHP Version: 5.4.1 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
47 - 28 = ?
Subscribe to this entry?

 
 [2012-04-30 02:23 UTC] fred dot stcm at gmail dot com
Description:
------------
PHP Array manual:
"Floats are also cast to integers, which means that the fractional part will be 
truncated. E.g. the key 8.7 will actually be stored under 8."

But this rule is ignored by SimpleXML object's array.

Test script:
---------------
$xml = simplexml_load_string("<xml><number>0</number><number>1</number></xml>");

$i = (int) 1;
$d = (float) 1;

$xml->number[$d] = 999;

echo $xml->number[$d] .", ". $xml->number[$i];

Expected result:
----------------
999, 999

Actual result:
--------------
999, 1

Patches

simplexml-patch (last revision 2012-04-30 20:58 UTC by felipe@php.net)

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-04-30 20:58 UTC] felipe@php.net
The following patch has been added/updated:

Patch Name: simplexml-patch
Revision:   1335819480
URL:        https://bugs.php.net/patch-display.php?bug=61877&patch=simplexml-patch&revision=1335819480
 [2020-03-27 01:04 UTC] carusogabriel@php.net
The following pull request has been associated:

Patch Name: Fix #61877: Make SimpleXMLElement respect PHP's array rule
On GitHub:  https://github.com/php/php-src/pull/5309
Patch:      https://github.com/php/php-src/pull/5309.patch
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Jan 27 08:01:26 2021 UTC