xref: /PHP-7.3/ext/xmlrpc/tests/bug50285.phpt (revision 782352c5)
1--TEST--
2Bug #50285 (xmlrpc does not preserve keys in encoded indexed arrays)
3--SKIPIF--
4<?php if (!extension_loaded("xmlrpc")) print "skip"; ?>
5--FILE--
6<?php
7
8function test1($func, $params) {
9    return array(1=>'One', 3=>'Three', 5=>'Five');
10}
11
12function test2($func, $params) {
13    return array('One', 'Three', 'Five', 5);
14}
15
16function test3($func, $params) {
17    return array('One', 3 => 'Three', 'Five' => 5, 'Six');
18}
19
20function test4($func, $params) {
21    return array('One', 'Three', 'Five', 'Six' => 6);
22}
23
24$server = xmlrpc_server_create();
25$result = xmlrpc_server_register_method($server, 'test1', 'test1');
26$HTTP_RAW_POST_DATA = <<<EOD
27<?xml version="1.0" encoding="UTF-8"?>
28<methodCall>
29<methodName>test1</methodName>
30<params />
31</methodCall>
32EOD;
33$response = xmlrpc_server_call_method($server, $HTTP_RAW_POST_DATA, null);
34var_dump(xmlrpc_decode($response));
35
36// ------------
37
38$server = xmlrpc_server_create();
39$result = xmlrpc_server_register_method($server, 'test2', 'test2');
40$HTTP_RAW_POST_DATA = <<<EOD
41<?xml version="1.0" encoding="UTF-8"?>
42<methodCall>
43<methodName>test2</methodName>
44<params />
45</methodCall>
46EOD;
47$response = xmlrpc_server_call_method($server, $HTTP_RAW_POST_DATA, null);
48var_dump(xmlrpc_decode($response));
49
50// ------------
51
52$server = xmlrpc_server_create();
53$result = xmlrpc_server_register_method($server, 'test3', 'test3');
54$HTTP_RAW_POST_DATA = <<<EOD
55<?xml version="1.0" encoding="UTF-8"?>
56<methodCall>
57<methodName>test3</methodName>
58<params />
59</methodCall>
60EOD;
61$response = xmlrpc_server_call_method($server, $HTTP_RAW_POST_DATA, null);
62var_dump(xmlrpc_decode($response));
63
64// ------------
65
66$server = xmlrpc_server_create();
67$result = xmlrpc_server_register_method($server, 'test4', 'test4');
68$HTTP_RAW_POST_DATA = <<<EOD
69<?xml version="1.0" encoding="UTF-8"?>
70<methodCall>
71<methodName>test4</methodName>
72<params />
73</methodCall>
74EOD;
75$response = xmlrpc_server_call_method($server, $HTTP_RAW_POST_DATA, null);
76var_dump(xmlrpc_decode($response));
77
78?>
79--EXPECT--
80array(3) {
81  [1]=>
82  string(3) "One"
83  [3]=>
84  string(5) "Three"
85  [5]=>
86  string(4) "Five"
87}
88array(4) {
89  [0]=>
90  string(3) "One"
91  [1]=>
92  string(5) "Three"
93  [2]=>
94  string(4) "Five"
95  [3]=>
96  int(5)
97}
98array(4) {
99  [0]=>
100  string(3) "One"
101  [3]=>
102  string(5) "Three"
103  ["Five"]=>
104  int(5)
105  [4]=>
106  string(3) "Six"
107}
108array(4) {
109  [0]=>
110  string(3) "One"
111  [1]=>
112  string(5) "Three"
113  [2]=>
114  string(4) "Five"
115  ["Six"]=>
116  int(6)
117}
118