|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74201 Strange SimpleXMLIterator Behaviour
Submitted: 2017-03-03 02:20 UTC Modified: 2017-03-03 09:00 UTC
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: dac514 at hotmail dot com Assigned:
Status: Wont fix Package: SimpleXML related
PHP Version: 5.4.35 OS: CentOS
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:
Solve the problem:
19 - 7 = ?
Subscribe to this entry?

 [2017-03-03 02:20 UTC] dac514 at hotmail dot com
We upgraded a legacy CentOS box from PHP 5.3.X to 5.4.35 and our XML code started to break.

I understand that these versions are not supported but for this particular project this is the best we can do. The weird thing is that this code works in 5.3, 5.5, 5.6, 7.0 ... But not 5.4.35 on CentOS. Running the attached test script on that particular version will echo "> YOU HAVE FAILED... "

I'm looking for some help, duplicate bugs that explain what is going on, or workarounds.

Thank you for your time.

Test script:

// ------------------------------------------------------------------------------------------------
// Functions
// ------------------------------------------------------------------------------------------------

function _iterator2array($iterator)
    $array = array();
    for ($iterator->rewind(); $iterator->valid(); $iterator->next())
        if (!array_key_exists($iterator->key(), $array)) $array[$iterator->key()] = array();

        if ($iterator->hasChildren()) $array[$iterator->key()][] = _iterator2array($iterator->current());
            $attributes = (array)$iterator->current();
            $array[$iterator->key()][] = reset($attributes);

    return $array;

function _xml2array($xml)
    // Strip the XML header if there is one and add a parent container
    if (preg_match('/<\?xml.*\?>/', $xml)) $xml = '<?xml version="1.0" encoding="UTF-8"?><root>'.preg_replace('/<\?xml.*\?>/', '', $xml).'</root>';
    $iterator = new SimpleXMLIterator($xml, NULL);

    return _iterator2array($iterator);

// ------------------------------------------------------------------------------------------------
// Input
// ------------------------------------------------------------------------------------------------

$xml = '<?xml version="1.0" encoding="UTF-8"?>\n<shipment-info xmlns=""><shipment-id>178011488481085223</shipment-id><shipment-status>created</shipment-status><tracking-pin>123456789012</tracking-pin><links><link rel="self" href="" media-type="application/vnd.cpc.shipment-v2+xml"/><link rel="details" href="" media-type="application/vnd.cpc.shipment-v2+xml"/><link rel="group" href="" media-type="application/vnd.cpc.shipment-v2+xml"/><link rel="price" href="" media-type="application/vnd.cpc.shipment-v2+xml"/><link rel="label" href="" media-type="application/pdf" index="0"/></links></shipment-info>';
$response = _xml2array($xml);

// ------------------------------------------------------------------------------------------------
// Test
// ------------------------------------------------------------------------------------------------

if (empty($response['shipment-info'][0]['tracking-pin'][0])) {
    echo "> YOU HAVE FAILED... \n";
} else {
    echo "> SUCCESS! \n";

Expected result:
`$response['shipment-info'][0]['tracking-pin'][0] = '123456789012'

Actual result:
$response['shipment-info'][0]['tracking-pin'][0] = ''


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-03-03 09:00 UTC]
-Status: Open +Status: Wont fix -PHP Version: Irrelevant +PHP Version: 5.4.35
 [2017-03-03 09:00 UTC]
Seems it was fixed in 5.5.27, which came with the fix for
and other similar bugs that were caused by whitespace issues. The change was fairly simple (within sxe_get_prop_hash) so you should be able to apply that to the 5.4 sources and build a custom patched version for yourself.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Tue May 24 03:05:44 2022 UTC