Bug #71996 [NEW]: Using references in arrays doesn't work like expected

From: Date: Fri, 08 Apr 2016 20:38:28 +0000
Subject: Bug #71996 [NEW]: Using references in arrays doesn't work like expected
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200445@lists.php.net to get a copy of this message
From: frankdeweger at gmail dot com Operating system: CentOS PHP version: 7.0.5 Package: SOAP related Bug Type: Bug Bug description:Using references in arrays doesn't work like expected Description: ------------ On of our suppliers expects heavily nested XML in the request we make. Constructions like the following are not uncommon in the requests we have to make to them: <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Body> <element1> <element2> <element3> <element4> <foo>bar</foo> </element4> </element3> </element2> </element1> </SOAP-ENV:Body> In order to create these nested structures, we used a helper as mentioned in the test script. In PHP 5.4.45 it produced the XML as stated above. However, under PHP 7.0.5, the following XML is generated: <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Body> <element1/> </SOAP-ENV:Body> For other people affected by this bug, if you replace the buildElement function with the following code, the generated XML is as expected. private function buildElement(array &$addTo, array $elements) { if (0 === count($elements)) { return; } $element = array_shift($elements); $addTo[$element] = array(); $this->buildElement($addTo, $elements); return; } Test script: --------------- <?php class Example { private function buildElement(array &$addTo, array $elements) { $previous = & $addTo; foreach ($elements as $element) { $previous[$element] = array(); $previous = & $previous[$element]; } } public function getSoapData() { $soapData = array(); $this->buildElement($soapData, array('element1', 'element2', 'element3', 'element4', 'foo')); $soapData['element1']['element2']['element3']['element4']['element4']['foo'] = 'bar'; return $soapData; } } $client = new SoapClient("some.wsdl"); $data = (new Example())->getSoapData(); $client->doSomething($data); Expected result: ---------------- The XML sent to our supplier looks like this: <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Body> <element1> <element2> <element3> <element4> <foo>bar</foo> </element4> </element3> </element2> </element1> </SOAP-ENV:Body> Actual result: -------------- The XML sent to our supplier looks like this: <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Body> <element1/> </SOAP-ENV:Body> -- Edit bug report at https://bugs.php.net/bug.php?id=71996&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71996&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71996&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71996&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=71996&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=71996&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=71996&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=71996&r=needscript Try newer version: https://bugs.php.net/fix.php?id=71996&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=71996&r=support Expected behavior: https://bugs.php.net/fix.php?id=71996&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=71996&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=71996&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=71996&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71996&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=71996&r=dst IIS Stability: https://bugs.php.net/fix.php?id=71996&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=71996&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=71996&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=71996&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=71996&r=mysqlcfg

« previous php.bugs (#200445) next »