php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72976 SOAP Request XML incorrect when array values modified via a by-ref foreach loop
Submitted: 2016-08-30 14:32 UTC Modified: 2016-08-30 15:24 UTC
From: phpbugreply at infosilem dot com Assigned:
Status: Duplicate Package: SOAP related
PHP Version: 7.0.10 OS: Windows
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: phpbugreply at infosilem dot com
New email:
PHP Version: OS:

 

 [2016-08-30 14:32 UTC] 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>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-08-30 15:24 UTC] nikic@php.net
-Status: Open +Status: Duplicate
 [2016-08-30 15:24 UTC] nikic@php.net
Duplicate of bug #71996, which is now fixed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Nov 24 02:01:28 2024 UTC