| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             [2017-03-03 09:00 UTC] requinix@php.net
 
-Status:      Open
+Status:      Wont fix
-PHP Version: Irrelevant
+PHP Version: 5.4.35
  [2017-03-03 09:00 UTC] requinix@php.net
  | 
    |||||||||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 11:00:01 2025 UTC | 
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] = ''