php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47492 SOAP_SINGLE_ELEMENT_ARRAYS has no effect
Submitted: 2009-02-24 13:33 UTC Modified: 2013-02-18 00:33 UTC
Votes:51
Avg. Score:4.7 ± 0.6
Reproduced:51 of 51 (100.0%)
Same Version:14 (27.5%)
Same OS:12 (23.5%)
From: florian dot eberle at gmail dot com Assigned:
Status: No Feedback Package: SOAP related
PHP Version: 5.2CVS-2009-02-24 (CVS) OS: Debian Lenny
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: florian dot eberle at gmail dot com
New email:
PHP Version: OS:

 

 [2009-02-24 13:33 UTC] florian dot eberle at gmail dot com
Description:
------------
The Feature SOAP_SINGLE_ELEMENT_ARRAYS has no effect when I try to get a resultset that sometimes contains only one Object. It always removes the array and returns the Object without the array.

See Example Code for additional information and feel free to contact me for additional information.

Reproduce code:
---------------
<?php
$options = array(
    'location' => 'http://u8020.intx.ch.netstream.com/dnssoap/soap.cgi' , 
    'uri' => 'http://dnstool.netstream.com/DnsAPI' , 
    'exceptions' => false , 
    'trace' => false , 
    'soap_version' => SOAP_1_1 , 
    'user_agent' => 'PHP DNS Client' , 
    'features' => SOAP_SINGLE_ELEMENT_ARRAYS
);
$soapserver = new SoapClient(null, $options);

//Watch Param type = A here  --> array 2 results expected here
$result = $soapserver->__soapCall('GetResourceRecords', 
    array(new SoapParam('wtf.com', 'zone') , new SoapParam('A', 'type')
    ));
var_dump($result);

//Watch Param type = MX here --> array with 1 result expected here
$result = $soapserver->__soapCall('GetResourceRecords', 
    array(new SoapParam('wtf.com', 'zone') , new SoapParam('MX', 'type')
    ));
var_dump($result);

?>

Expected result:
----------------
array(2) {
  ["total"]=>
  string(1) "2"
  ["records"]=>
  array(2) {
    [0]=>
    object(stdClass)#4 (7) {
      ["name"]=>
      string(4) "test"
      ["class"]=>
      string(2) "IN"
      ["data"]=>
      string(9) "127.0.0.1"
      ["id"]=>
      string(6) "160441"
      ["parameter"]=>
      string(0) ""
      ["ttl"]=>
      string(0) ""
      ["type"]=>
      string(1) "A"
    }
    [1]=>
    object(stdClass)#5 (7) {
      ["name"]=>
      string(4) "test"
      ["class"]=>
      string(2) "IN"
      ["data"]=>
      string(9) "127.0.0.1"
      ["id"]=>
      string(6) "160442"
      ["parameter"]=>
      string(0) ""
      ["ttl"]=>
      string(0) ""
      ["type"]=>
      string(1) "A"
    }
  }
}

array(2) {
  ["total"]=>
  string(1) "2"
  ["records"]=>
  array(1) {
    [0]=>
    object(stdClass)#4 (7) {
      ["name"]=>
      string(4) "stop.bugging.me"
      ["class"]=>
      string(2) "IN"
      ["data"]=>
      string(9) "32"
      ["id"]=>
      string(6) "160443"
      ["parameter"]=>
      string(0) "50"
      ["ttl"]=>
      string(0) "1337"
      ["type"]=>
      string(1) "MX"
    }
  }
}

Actual result:
--------------
array(2) {
  ["total"]=>
  string(1) "2"
  ["records"]=>
  array(2) {
    [0]=>
    object(stdClass)#4 (7) {
      ["name"]=>
      string(4) "test"
      ["class"]=>
      string(2) "IN"
      ["data"]=>
      string(9) "127.0.0.1"
      ["id"]=>
      string(6) "160441"
      ["parameter"]=>
      string(0) ""
      ["ttl"]=>
      string(0) ""
      ["type"]=>
      string(1) "A"
    }
    [1]=>
    object(stdClass)#5 (7) {
      ["name"]=>
      string(4) "test"
      ["class"]=>
      string(2) "IN"
      ["data"]=>
      string(9) "127.0.0.1"
      ["id"]=>
      string(6) "160442"
      ["parameter"]=>
      string(0) ""
      ["ttl"]=>
      string(0) ""
      ["type"]=>
      string(1) "A"
    }
  }
}
array(2) {
  ["total"]=>
  string(1) "1"
  ["records"]=>
  object(stdClass)#6 (7) {
    ["name"]=>
    string(15) "stop.bugging.me"
    ["class"]=>
    string(2) "IN"
    ["data"]=>
    string(2) "32"
    ["id"]=>
    string(6) "160443"
    ["parameter"]=>
    string(2) "50"
    ["ttl"]=>
    string(4) "1337"
    ["type"]=>
    string(2) "MX"
  }
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-27 08:35 UTC] niek at signet dot nl
I've the same problem; but I use WSDL with my SOAP.
 [2009-11-27 13:45 UTC] niek at signet dot nl
This bug was filed a long time ago, still no replies. Is there going to be some kind of fix for this?
 [2010-06-20 21:27 UTC] felipe@php.net
-Status: Open +Status: Feedback
 [2010-06-20 21:27 UTC] felipe@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2010-11-04 07:55 UTC] timothee dot groleau at mig33global dot com
Same problem here. xsi:type="ns2:Vector" entries are not translated to arrays if there is only one element inside. Example below:



soap client created like so:
============================================================
$client = new soapclient(null, array(
  'location' => $soap_ejb_service_url,
  'uri' => $soap_ejb_service_name,
  'features' => SOAP_SINGLE_ELEMENT_ARRAYS | SOAP_USE_XSI_ARRAY_TYPE,
  'trace' => true)
);
$response = $client->__soapCall($function, $parameters);
============================================================


raw soap response:
============================================================
<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<ns1:searchChatroomResponse xmlns:ns1="urn:fusion" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<return xmlns:ns2="http://xml.apache.org/xml-soap" xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">totalpages</key>
<value xsi:type="xsd:double">1.0</value>
</item>
<item>
<key xsi:type="xsd:string">totalresults</key>
<value xsi:type="xsd:int">1</value>
</item>
<item>
<key xsi:type="xsd:string">chatrooms</key>
<value xsi:type="ns2:Vector">
<item xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">name</key>
<value xsi:type="xsd:string">tim_test</value>
</item>
<item>
<key xsi:type="xsd:string">id</key>
<value xsi:type="xsd:string">6</value>
</item>
<item>
<key xsi:type="xsd:string">status</key>
<value xsi:type="xsd:string">ACTIVE</value>
</item>
<item>
<key xsi:type="xsd:string">language</key>
<value xsi:type="xsd:string">ENG</value>
</item>
</item>
</value>
</item>
<item>
<key xsi:type="xsd:string">page</key>
<value xsi:type="xsd:int">1</value>
</item>
</return>
</ns1:searchChatroomResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
============================================================


$response returned by php client:
============================================================
array(4) {
  ["totalpages"]=>
  float(1)
  ["totalresults"]=>
  int(1)
  ["chatrooms"]=>
  object(stdClass)#2 (1) {
    ["item"]=>
    array(16) {
      ["name"]=>
      string(8) "tim_test"
      ["id"]=>
      string(1) "6"
      ["status"]=>
      string(6) "ACTIVE"
      ["language"]=>
      string(3) "ENG"
    }
  }
  ["page"]=>
  int(1)
}
============================================================
 [2010-11-04 08:08 UTC] timothee dot groleau at mig33global dot com
Oh duh, I forgot to add some version information:

$ php -version
PHP 5.3.3 (cli) (built: Oct 29 2010 14:24:39) 
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies


I'm on Mac OS, php was installed from macports
 [2012-06-13 12:42 UTC] jboffel at gmail dot com
Hi all,

I think for people without WSDL, you shouldn't expect SOAP_SINGLE_ELEMENT_ARRAYS to work.

To know it, SoapClient need a XSD saying it could be or not more than one result to decide it must be in array or not.

Just with SOAP answer it is technically impossible to make a difference between an anwser that is just 1 element but could have N and an answer that is known to be only 1.

Exemple :
<body>
<brotherdetail>age: 17</brotherdetail>
</body>

<body>
<brotherdetail>age: 17</brotherdetail>
<brotherdetail>sister : 1</brotherdetail>
</body>

In first case, if you don't have a XSD to say brotherdetail is a type and have rule maxOccurs = unbounded, how do you expect SoapClient will know it could have been more than one detail ?
Of course with second example, SoapClient will now it could be because it'll find more than one so it will naturally make an array...
 [2013-02-18 00:33 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 17:01:58 2024 UTC