Skip to content

Commit b49aaf4

Browse files
committed
Change to ValueError
1 parent 6daf60a commit b49aaf4

7 files changed

Lines changed: 31 additions & 20 deletions

File tree

NEWS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ PHP NEWS
5252
. Fixed header injection through the Content-Type context option, the
5353
soapaction and the cookie names and values. (David Carlier)
5454
. Fixed the SoapClient and SoapServer "classmap" option to reject arrays
55-
containing integer keys. (Weilin Du, David Carlier)
55+
containing integer keys, and made SoapClient throw ValueError for invalid
56+
"classmap" options. (Weilin Du, David Carlier)
5657

5758
- MBString:
5859
. Fixed bug GH-22779 (mb_strrpos() returns the wrong position for a negative

UPGRADING

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ PHP 8.6 UPGRADE NOTES
157157
- SOAP:
158158
. The "classmap" option of SoapClient and SoapServer now rejects arrays
159159
containing integer keys. Previously, sparse integer-keyed and mixed-keyed
160-
arrays could be accepted.
160+
arrays could be accepted. SoapClient now throws a ValueError for invalid
161+
"classmap" options, also when the "exceptions" option is disabled.
161162
. WSDL/XML Schema parsing now rejects out-of-range integer values for
162163
occurrence constraints and integer restriction facets. Negative minOccurs
163164
and maxOccurs values are rejected as well.

ext/soap/soap.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2245,7 +2245,11 @@ PHP_METHOD(SoapClient, __construct)
22452245
if ((tmp = zend_hash_str_find(ht, "classmap", sizeof("classmap")-1)) != NULL &&
22462246
Z_TYPE_P(tmp) == IS_ARRAY) {
22472247
if (UNEXPECTED(!soap_class_map_has_only_string_keys(Z_ARRVAL_P(tmp)))) {
2248-
php_error_docref(NULL, E_ERROR, "'classmap' option must be an associative array");
2248+
zend_argument_value_error(2, "\"classmap\" option must be an associative array");
2249+
if (context) {
2250+
zend_list_delete(context->res);
2251+
}
2252+
goto finish;
22492253
}
22502254
ZVAL_COPY(Z_CLIENT_CLASSMAP_P(this_ptr), tmp);
22512255
}
@@ -2324,6 +2328,8 @@ PHP_METHOD(SoapClient, __construct)
23242328
if (typemap_ht) {
23252329
soap_client_object_fetch(Z_OBJ_P(this_ptr))->typemap = soap_create_typemap(sdl, typemap_ht);
23262330
}
2331+
2332+
finish:
23272333
SOAP_CLIENT_END_CODE();
23282334
}
23292335
/* }}} */

ext/soap/tests/bugs/gh16256.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ try {
2020
}
2121
?>
2222
--EXPECT--
23-
SoapClient::__construct(): 'classmap' option must be an associative array
23+
SoapClient::__construct(): Argument #2 ($options) "classmap" option must be an associative array
2424
SoapServer::__construct(): Argument #2 ($options) "classmap" option must be an associative array

ext/soap/tests/classmap_invalid_keys.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,16 @@ SoapServer: OK
5252
SoapClient: OK
5353
SoapServer: OK
5454
-- packed --
55-
SoapClient::__construct(): 'classmap' option must be an associative array
55+
SoapClient::__construct(): Argument #2 ($options) "classmap" option must be an associative array
5656
SoapServer::__construct(): Argument #2 ($options) "classmap" option must be an associative array
5757
-- sparse numeric --
58-
SoapClient::__construct(): 'classmap' option must be an associative array
58+
SoapClient::__construct(): Argument #2 ($options) "classmap" option must be an associative array
5959
SoapServer::__construct(): Argument #2 ($options) "classmap" option must be an associative array
6060
-- numeric string --
61-
SoapClient::__construct(): 'classmap' option must be an associative array
61+
SoapClient::__construct(): Argument #2 ($options) "classmap" option must be an associative array
6262
SoapServer::__construct(): Argument #2 ($options) "classmap" option must be an associative array
6363
-- mixed --
64-
SoapClient::__construct(): 'classmap' option must be an associative array
64+
SoapClient::__construct(): Argument #2 ($options) "classmap" option must be an associative array
6565
SoapServer::__construct(): Argument #2 ($options) "classmap" option must be an associative array
6666
-- associative --
6767
SoapClient: OK

ext/soap/tests/classmap_invalid_keys_error_types.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
SoapClient and SoapServer report an invalid classmap option differently
2+
SoapClient and SoapServer report an invalid classmap option as ValueError
33
--EXTENSIONS--
44
soap
55
--FILE--
@@ -28,5 +28,5 @@ try {
2828

2929
?>
3030
--EXPECT--
31-
SoapClient: SoapFault: SoapClient::__construct(): 'classmap' option must be an associative array
31+
SoapClient: ValueError: SoapClient::__construct(): Argument #2 ($options) "classmap" option must be an associative array
3232
SoapServer: ValueError: SoapServer::__construct(): Argument #2 ($options) "classmap" option must be an associative array
Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
--TEST--
2-
SoapClient reports an invalid classmap option as a fatal error when exceptions are disabled
2+
SoapClient reports an invalid classmap option as ValueError when exceptions are disabled
33
--EXTENSIONS--
44
soap
55
--FILE--
66
<?php
77

8-
new SoapClient(null, [
9-
'location' => 'http://example.com/',
10-
'uri' => 'urn:test',
11-
'exceptions' => false,
12-
'classmap' => ['type' => 'stdClass', 1 => 'stdClass'],
13-
]);
14-
echo 'not reached', PHP_EOL;
8+
try {
9+
new SoapClient(null, [
10+
'location' => 'http://example.com/',
11+
'uri' => 'urn:test',
12+
'exceptions' => false,
13+
'classmap' => ['type' => 'stdClass', 1 => 'stdClass'],
14+
]);
15+
} catch (Throwable $e) {
16+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
17+
}
1518

1619
?>
17-
--EXPECTF--
18-
Fatal error: SoapClient::__construct(): 'classmap' option must be an associative array in %s on line %d
20+
--EXPECT--
21+
ValueError: SoapClient::__construct(): Argument #2 ($options) "classmap" option must be an associative array

0 commit comments

Comments
 (0)