Bug #72976 [NEW]: SOAP Request XML incorrect when array values modified via a by-ref foreach loop
| From: | phpbugreply at infosilem dot com | Date: | Tue, 30 Aug 2016 14:32:49 +0000 |
| Subject: | Bug #72976 [NEW]: SOAP Request XML incorrect when array values modified via a by-ref foreach loop | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-203683@lists.php.net to get a copy of this message | ||
From: phpbugreply at infosilem dot com
Operating system: Windows
PHP version: 7.0.10
Package: SOAP related
Bug Type: Bug
Bug description:SOAP Request XML incorrect when array values modified via a by-ref foreach loop
Description:
------------
I am calling a SOAP service (hosted by a IIS ASP.NET application) via
PHP 7.0.10 (same bug on 7.0.0) and the SOAP request's XML is missing
some information. The exact same code works as expected on PHP 5.6.7.
This only appears to occur when altering the parameters sent to the SOAP
call via a by-ref foreach.
e.g doing this will cause the problem:
foreach($dates as &$date) {
$date = new stdClass();
$date->value = 50;
}
But using a typical loop to edit the values works fine:
for($i = count($dates) - 1; $i >= 0; $i++) {
$dates[i] = new stdClass();
$dates[i]->value = 50;
}
Test script:
---------------
$date1 = new stdClass();
$date1->value = 10;
$date2 = new stdClass();
$date2->value = 30;
$dates = [$date1, $date2];
$value = 50;
//Modify the array's values via a by-ref foreach
foreach($dates as &$date) {
$date = new stdClass();
$date->value = $value++;
}
$params = new stdClass();
$params->Dates = $dates;
$options = new stdClass();
$options->Params = $params;
$client = new SoapClient(...);
$client->TestPhp($options);
Expected result:
----------------
In PHP 5.6, this works as expected and produces the following:
var_dump for $params before call: object(stdClass)#316 (1) {
["Dates"]=> array(2) { [0]=> object(stdClass)#255 (1) {
["value"]=> int(50) } [1]=> &object(stdClass)#315 (1)
{ ["value"]=> int(51) } } }
Soap Request XML:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://www.xxxxxxxx.com/">
<SOAP-ENV:Body>
<ns1:TestPhp>
<ns1:Params>
<ns1:Dates id="ref1">
<ns1:WebDateTime>
<ns1:value>50</ns1:value>
</ns1:WebDateTime>
<ns1:WebDateTime>
<ns1:value>51</ns1:value>
</ns1:WebDateTime>
</ns1:Dates>
</ns1:Params>
</ns1:TestPhp>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Actual result:
--------------
In PHP 7.0, we get the following instead:
The var_dump for $params is identical to the PHP 5.6 version above, so
the data is correct (and identical to PHP 5.6), but somehow the
SoapClient does not produce the correct request xml in this case - it is
missing the date objects' "value" tags:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://www.xxxxxxxx.com/">
<SOAP-ENV:Body>
<ns1:TestPhp>
<ns1:Params>
<ns1:Dates>
<ns1:WebDateTime id="ref1" />
<ns1:WebDateTime id="ref2" />
</ns1:Dates>
</ns1:Params>
</ns1:TestPhp>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
--
Edit bug report at https://bugs.php.net/bug.php?id=72976&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72976&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72976&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72976&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=72976&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=72976&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=72976&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=72976&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=72976&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=72976&r=support
Expected behavior: https://bugs.php.net/fix.php?id=72976&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=72976&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=72976&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=72976&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72976&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=72976&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=72976&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=72976&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72976&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=72976&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=72976&r=mysqlcfg