Bug #71996 [Com]: Using references in arrays doesn't work like expected
| From: | nikola at petkanski dot com | Date: | Mon, 13 Jun 2016 14:50:52 +0000 |
| Subject: | Bug #71996 [Com]: Using references in arrays doesn't work like expected | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-201574@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71996&edit=1
ID: 71996
Comment by: nikola at petkanski dot com
Reported by: frankdeweger at gmail dot com
Summary: Using references in arrays doesn't work like
expected
Status: Open
Type: Bug
Package: SOAP related
Operating System: CentOS
PHP Version: 7.0.5
Block user comment: N
Private report: N
New Comment:
Forgot to mention the case is tested and works in PHP 5.6, but fails in PHP 7.0.
Previous Comments:
------------------------------------------------------------------------
[2016-06-13 14:49:52] nikola at petkanski dot com
Probably has something with the fact PHP 7 completely revamped how zvars work.
We have the same problem. In order to reproduce the problem please use the following soap server and
client combo. It clearly illustrates where the problem lies.
Soap Server:
https://gist.github.com/dinamic/29e7f7d6bd3085d903dfa1634c8cd65c
Soap Client:
https://gist.github.com/dinamic/e7e2d904c76553bda390e5d9b1a5bcca
------------------------------------------------------------------------
[2016-04-08 21:29:25] frankdeweger at gmail dot com
I made small error in my test script, the correct code is:
public function getSoapData()
{
$soapData = array();
$this->buildElement($soapData, array('element1', 'element2',
'element3', 'element4', 'foo'));
$soapData['element1']['element2']['element3']['element4']['foo']
= 'bar';
return $soapData;
}
------------------------------------------------------------------------
[2016-04-08 20:38:21] frankdeweger at gmail dot com
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 this bug report at https://bugs.php.net/bug.php?id=71996&edit=1