|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-08-30 15:24 UTC] nikic@php.net
-Status: Open
+Status: Duplicate
[2016-08-30 15:24 UTC] nikic@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 19:00:02 2025 UTC |
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>