|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41097 ext/soap returning associative array as indexed without using WSDL
Submitted: 2007-04-16 06:59 UTC Modified: 2007-05-03 06:40 UTC
Avg. Score:4.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: r dot korving at xit dot nl Assigned: dmitry (profile)
Status: Closed Package: SOAP related
PHP Version: 5.2.1 OS: Debian
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: r dot korving at xit dot nl
New email:
PHP Version: OS:


 [2007-04-16 06:59 UTC] r dot korving at xit dot nl
Returning array('5' => 'Foo', '10' => 'Bar') from a SoapServer handler class ends up as array(0 => 'Foo', 1 => 'Bar') at the client end. But array('a' => 'Foo', 'b' => 'Bar') does end up correctly. It only fails with numeric keys. I'm not using WSDL in this case. I think integer keys that are not in a simple 0..n range should end up in an associative array, not indexed with new 0..n keys.

Reproduce code:

class MyHandler
  public function getData()
    return array('5' => 'Foo', '10' => 'Bar');

// initialize soap-server:

$soap = new SoapServer(null, array('uri' => 'http://uri/', 'encoding' => 'ISO-8859-1'));


Expected result:
array('5' => 'Foo', '10' => 'Bar')

Actual result:
array(0 => 'Foo', 1 => 'Bar')


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-02 08:22 UTC]
Your expectation is wrong because PHP converts numeric string indeces into integer.

$ sapi/cli/php -r 'var_dump(array("5" => "Foo", "10" => "Bar"));'
array(2) {
  string(3) "Foo"
  string(3) "Bar"

BTW I fixed ext/soap to use Apache:Map instead of SOAP-ENC:Array in case of partial arrays (missing indeces).

FIXED in CVS HEAD and PHP_5_2.
 [2007-05-03 06:40 UTC] r dot korving at xit dot nl

I don't mind it using integers at all, as long as it doesn't start renumbering from 0 to N. Thanks for the fix.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 30 11:01:31 2024 UTC