Bug #74201 [NEW]: Strange SimpleXMLIterator Behaviour

From: Date: Fri, 03 Mar 2017 02:20:40 +0000
Subject: Bug #74201 [NEW]: Strange SimpleXMLIterator Behaviour
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-207671@lists.php.net to get a copy of this message
From: dac514 at hotmail dot com Operating system: CentOS PHP version: Irrelevant Package: SimpleXML related Bug Type: Bug Bug description:Strange SimpleXMLIterator Behaviour Description: ------------ 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: --------------- <?php // ------------------------------------------------------------------------------------------------ // 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()); else { $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="http://www.canadapost.ca/ws/shipment"><shipment-id>178011488481085223</shipment-id><shipment-status>created</shipment-status><tracking-pin>123456789012</tracking-pin><links><link rel="self" href="https://ct.soa-gw.canadapost.ca/rs/0007174985/0007174985/shipment/178011488481085223" media-type="application/vnd.cpc.shipment-v2+xml"/><link rel="details" href="https://ct.soa-gw.canadapost.ca/rs/0007174985/0007174985/shipment/178011488481085223/details" media-type="application/vnd.cpc.shipment-v2+xml"/><link rel="group" href="https://ct.soa-gw.canadapost.ca/rs/0007174985/0007174985/shipment?groupId=ssense" media-type="application/vnd.cpc.shipment-v2+xml"/><link rel="price" href="https://ct.soa-gw.canadapost.ca/rs/0007174985/0007174985/shipment/178011488481085223/price" media-type="application/vnd.cpc.shipment-v2+xml"/><link rel="label" href="https://ct.soa-gw.canadapost.ca/rs/artifact/4096ae613c3f147c/10000352593/0" 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] = '' -- Edit bug report at https://bugs.php.net/bug.php?id=74201&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=74201&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=74201&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=74201&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=74201&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=74201&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=74201&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=74201&r=needscript Try newer version: https://bugs.php.net/fix.php?id=74201&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=74201&r=support Expected behavior: https://bugs.php.net/fix.php?id=74201&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=74201&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=74201&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=74201&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74201&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=74201&r=dst IIS Stability: https://bugs.php.net/fix.php?id=74201&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=74201&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=74201&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=74201&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=74201&r=mysqlcfg

« previous php.bugs (#207671) next »