PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Web Services » SOAP » Bug #10131

incorrect return value in case of an empty array

Details

Submitted2007-02-20 00:39 UTC
Fromthe-savior at freenet dot de
Assignedcweiske
StatusClosed
PackageSOAP
PHP Version4.4.1
OSdebian linux etch
Roadmaps(Not assigned)

Comments

[2007-02-20 00:39 UTC] the-savior at freenet dot de

Description:
------------
if a soap server response an empty array (attribute xsi:nil="true"), PEAR::SOAP on client side returns an empty string instead of an empty array. this can be really confusing if you want to count the elements of the returned array for example.

Sample:
<?php
...
// get the wsdl-proxy
$oProxyRef = $oWSDLRef->getProxy();

// call a function which should return an array
$mResult = $oProxyRef->returnArray();

/* --- soap response ---
...
<ns4:returnArrayResponse>
<list xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="xsd:int[0]" xsi:nil="true"/>
</ns4:returnArrayResponse>
...
*/

var_dump($mResult); // prints: string(0) ""
count($mResult); // 1
...
?>

after some debugging i found a solution to fix this problem:
i think the method "buildResponse()" in Parser.php refers a wrong value when creating a new Soap_Value on Line 221:

current Parser.php
[Line 210] // Add current node's value.
[Line 211] if ($response) {
[Line 212] $nqn =& new Qname($this->message[$pos]['name'], $this->message[$pos]['namespace']);
[Line 213] $tqn =& new Qname($this->message[$pos]['type'], $this->message[$pos]['type_namespace']);
[Line 214] $response =& new SOAP_Value($nqn->fqn(), $tqn->fqn(), $response, $attrs);
[Line 215] if (isset($this->message[$pos]['arrayType'])) {
[Line 216] $response->arrayType = $this->message[$pos]['arrayType'];
[Line 217] }
[Line 218] } else {
[Line 219] $nqn =& new Qname($this->message[$pos]['name'], $this->message[$pos]['namespace']);
[Line 220] $tqn =& new Qname($this->message[$pos]['type'], $this->message[$pos]['type_namespace']);
[Line 221] $response =& new SOAP_Value($nqn->fqn(), $tqn->fqn(), $this->message[$pos]['cdata'], $attrs);
[Line 222] }

fixed Parser.php
[Line 210] // Add current node's value.
[Line 211] if ($response) {
[Line 212] $nqn =& new Qname($this->message[$pos]['name'], $this->message[$pos]['namespace']);
[Line 213] $tqn =& new Qname($this->message[$pos]['type'], $this->message[$pos]['type_namespace']);
[Line 214] $response =& new SOAP_Value($nqn->fqn(), $tqn->fqn(), $response, $attrs);
[Line 215] if (isset($this->message[$pos]['arrayType'])) {
[Line 216] $response->arrayType = $this->message[$pos]['arrayType'];
[Line 217] }
[Line 218] } else {
[Line 219] $nqn =& new Qname($this->message[$pos]['name'], $this->message[$pos]['namespace']);
[Line 220] $tqn =& new Qname($this->message[$pos]['type'], $this->message[$pos]['type_namespace']);
[Line 221*] // Check if value is an empty array
[Line 222*] if ($tqn->name == 'Array') {
[Line 223*] $response =& new SOAP_Value($nqn->fqn(), $tqn->fqn(), array(), $attrs);
[Line 224*] } else {
[Line 225*] $response =& new SOAP_Value($nqn->fqn(), $tqn->fqn(), $this->message[$pos]['cdata'], $attrs);
[Line 226*] }
[Line 227] }

maybe the wrong position to fix the problem - but for me it worked.