Bug #72976 [Opn->Dup]: SOAP Request XML incorrect when array values modified via a by-ref foreach loop

From: Date: Tue, 30 Aug 2016 15:24:28 +0000
Subject: Bug #72976 [Opn->Dup]: SOAP Request XML incorrect when array values modified via a by-ref foreach loop
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-203687@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72976&edit=1 ID: 72976 Updated by: nikic@php.net Reported by: phpbugreply at infosilem dot com Summary: SOAP Request XML incorrect when array values modified via a by-ref foreach loop -Status: Open +Status: Duplicate Type: Bug Package: SOAP related Operating System: Windows PHP Version: 7.0.10 Block user comment: N Private report: N New Comment: Duplicate of bug #71996, which is now fixed. Previous Comments: ------------------------------------------------------------------------ [2016-08-30 14:32:44] phpbugreply at infosilem dot com 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 this bug report at https://bugs.php.net/bug.php?id=72976&edit=1

« previous php.bugs (#203687) next »