Skip to content

Commit 955f289

Browse files
committed
Promote warnings to exceptions in ext/soap and ext/xmlwriter
1 parent 517c993 commit 955f289

File tree

7 files changed

+100
-77
lines changed

7 files changed

+100
-77
lines changed

ext/soap/soap.c

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ static void soap_error_handler(int error_num, const char *error_filename, const
149149
if ((tmp = zend_hash_str_find(Z_OBJPROP_P(ZEND_THIS),"service", sizeof("service")-1)) != NULL) { \
150150
ss = (soapServicePtr)zend_fetch_resource_ex(tmp, "service", le_service); \
151151
} else { \
152-
php_error_docref(NULL, E_WARNING, "Can not fetch service object"); \
152+
zend_throw_error(NULL, "Cannot fetch SoapServer object"); \
153153
SOAP_SERVER_END_CODE(); \
154-
return; \
154+
RETURN_THROWS(); \
155155
} \
156156
}
157157

@@ -525,9 +525,10 @@ PHP_METHOD(SoapParam, __construct)
525525
if (zend_parse_parameters(ZEND_NUM_ARGS(), "zs", &data, &name, &name_length) == FAILURE) {
526526
RETURN_THROWS();
527527
}
528+
528529
if (name_length == 0) {
529-
php_error_docref(NULL, E_WARNING, "Invalid parameter name");
530-
return;
530+
zend_argument_value_error(2, "cannot be empty");
531+
RETURN_THROWS();
531532
}
532533

533534
this_ptr = ZEND_THIS;
@@ -559,12 +560,12 @@ PHP_METHOD(SoapHeader, __construct)
559560
ZEND_PARSE_PARAMETERS_END();
560561

561562
if (ns_len == 0) {
562-
php_error_docref(NULL, E_WARNING, "Invalid namespace");
563-
return;
563+
zend_argument_value_error(1, "cannot be empty");
564+
RETURN_THROWS();
564565
}
565566
if (name_len == 0) {
566-
php_error_docref(NULL, E_WARNING, "Invalid header name");
567-
return;
567+
zend_argument_value_error(2, "cannot be empty");
568+
RETURN_THROWS();
568569
}
569570

570571
this_ptr = ZEND_THIS;
@@ -579,13 +580,15 @@ PHP_METHOD(SoapHeader, __construct)
579580
if (ZSTR_LEN(actor_str) > 2) {
580581
add_property_stringl(this_ptr, "actor", ZSTR_VAL(actor_str), ZSTR_LEN(actor_str));
581582
} else {
582-
php_error_docref(NULL, E_WARNING, "Invalid actor");
583+
zend_argument_value_error(2, "must be longer than 2 characters");
584+
RETURN_THROWS();
583585
}
584586
} else if (!actor_is_null) {
585587
if ((actor_long == SOAP_ACTOR_NEXT || actor_long == SOAP_ACTOR_NONE || actor_long == SOAP_ACTOR_UNLIMATERECEIVER)) {
586588
add_property_long(this_ptr, "actor", actor_long);
587589
} else {
588-
php_error_docref(NULL, E_WARNING, "Invalid actor");
590+
zend_argument_value_error(5, "must be either SOAP_ACTOR_NEXT, SOAP_ACTOR_NONE or SOAP_ACTOR_UNLIMATERECEIVER");
591+
RETURN_THROWS();
589592
}
590593
}
591594
}
@@ -624,9 +627,10 @@ PHP_METHOD(SoapFault, __construct)
624627
}
625628

626629
if ((code_str || code_ht) && (fault_code == NULL || fault_code_len == 0)) {
627-
php_error_docref(NULL, E_WARNING, "Invalid fault code");
628-
return;
630+
zend_argument_value_error(1, "is not a valid fault code");
631+
RETURN_THROWS();
629632
}
633+
630634
if (name != NULL && name_len == 0) {
631635
name = NULL;
632636
}
@@ -700,8 +704,8 @@ PHP_METHOD(SoapVar, __construct)
700704
if (zend_hash_index_exists(&SOAP_GLOBAL(defEncIndex), type)) {
701705
add_property_long(this_ptr, "enc_type", type);
702706
} else {
703-
php_error_docref(NULL, E_WARNING, "Invalid type ID");
704-
return;
707+
zend_argument_value_error(2, "is not a valid encoding");
708+
RETURN_THROWS();
705709
}
706710
}
707711

@@ -739,7 +743,7 @@ static HashTable* soap_create_typemap(sdlPtr sdl, HashTable *ht) /* {{{ */
739743
zend_string *name;
740744

741745
if (Z_TYPE_P(tmp) != IS_ARRAY) {
742-
php_error_docref(NULL, E_WARNING, "Wrong 'typemap' option");
746+
zend_type_error("SoapHeader::__construct(): \"typemap\" option must be of type array, %s given", zend_zval_type_name(tmp));
743747
return NULL;
744748
}
745749
ht2 = Z_ARRVAL_P(tmp);
@@ -971,12 +975,14 @@ PHP_METHOD(SoapServer, setPersistence)
971975
value == SOAP_PERSISTENCE_REQUEST) {
972976
service->soap_class.persistence = value;
973977
} else {
974-
php_error_docref(NULL, E_WARNING, "Tried to set persistence with bogus value (" ZEND_LONG_FMT ")", value);
975-
return;
978+
zend_argument_value_error(
979+
1, "must be either SOAP_PERSISTENCE_SESSION or SOAP_PERSISTENCE_REQUEST when the SOAP server is used in class mode"
980+
);
981+
RETURN_THROWS();
976982
}
977983
} else {
978-
php_error_docref(NULL, E_WARNING, "Tried to set persistence when you are using you SOAP SERVER in function mode, no persistence needed");
979-
return;
984+
zend_throw_error(NULL, "SoapServer::setPersistence(): Persistence cannot be set when the SOAP server is used in function mode");
985+
RETURN_THROWS();
980986
}
981987

982988
SOAP_SERVER_END_CODE();
@@ -988,37 +994,29 @@ PHP_METHOD(SoapServer, setPersistence)
988994
PHP_METHOD(SoapServer, setClass)
989995
{
990996
soapServicePtr service;
991-
zend_string *classname;
992-
zend_class_entry *ce;
997+
zend_class_entry *ce = NULL;
993998
int num_args = 0;
994999
zval *argv = NULL;
9951000

996-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S*", &classname, &argv, &num_args) == FAILURE) {
1001+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "C*", &ce, &argv, &num_args) == FAILURE) {
9971002
RETURN_THROWS();
9981003
}
9991004

10001005
SOAP_SERVER_BEGIN_CODE();
10011006

10021007
FETCH_THIS_SERVICE(service);
10031008

1004-
ce = zend_lookup_class(classname);
1009+
service->type = SOAP_CLASS;
1010+
service->soap_class.ce = ce;
10051011

1006-
if (ce) {
1007-
service->type = SOAP_CLASS;
1008-
service->soap_class.ce = ce;
1009-
1010-
service->soap_class.persistence = SOAP_PERSISTENCE_REQUEST;
1011-
service->soap_class.argc = num_args;
1012-
if (service->soap_class.argc > 0) {
1013-
int i;
1014-
service->soap_class.argv = safe_emalloc(sizeof(zval), service->soap_class.argc, 0);
1015-
for (i = 0;i < service->soap_class.argc;i++) {
1016-
ZVAL_COPY(&service->soap_class.argv[i], &argv[i]);
1017-
}
1012+
service->soap_class.persistence = SOAP_PERSISTENCE_REQUEST;
1013+
service->soap_class.argc = num_args;
1014+
if (service->soap_class.argc > 0) {
1015+
int i;
1016+
service->soap_class.argv = safe_emalloc(sizeof(zval), service->soap_class.argc, 0);
1017+
for (i = 0;i < service->soap_class.argc;i++) {
1018+
ZVAL_COPY(&service->soap_class.argv[i], &argv[i]);
10181019
}
1019-
} else {
1020-
php_error_docref(NULL, E_WARNING, "Tried to set a non existent class (%s)", ZSTR_VAL(classname));
1021-
return;
10221020
}
10231021

10241022
SOAP_SERVER_END_CODE();
@@ -1122,14 +1120,15 @@ PHP_METHOD(SoapServer, addFunction)
11221120
zend_function *f;
11231121

11241122
if (Z_TYPE_P(tmp_function) != IS_STRING) {
1125-
php_error_docref(NULL, E_WARNING, "Tried to add a function that isn't a string");
1126-
return;
1123+
zend_argument_type_error(1, "must contain only strings");
1124+
RETURN_THROWS();
11271125
}
11281126

11291127
key = zend_string_tolower(Z_STR_P(tmp_function));
11301128

11311129
if ((f = zend_hash_find_ptr(EG(function_table), key)) == NULL) {
1132-
php_error_docref(NULL, E_WARNING, "Tried to add a non existent function '%s'", Z_STRVAL_P(tmp_function));
1130+
zend_type_error("SoapServer::addFunction(): Function \"%s\" not found", Z_STRVAL_P(tmp_function));
1131+
RETURN_THROWS();
11331132
return;
11341133
}
11351134

@@ -1146,8 +1145,8 @@ PHP_METHOD(SoapServer, addFunction)
11461145
key = zend_string_tolower(Z_STR_P(function_name));
11471146

11481147
if ((f = zend_hash_find_ptr(EG(function_table), key)) == NULL) {
1149-
php_error_docref(NULL, E_WARNING, "Tried to add a non existent function '%s'", Z_STRVAL_P(function_name));
1150-
return;
1148+
zend_argument_type_error(1, "must be a valid callback, function \"%s\" not found", Z_STRVAL_P(function_name));
1149+
RETURN_THROWS();
11511150
}
11521151
if (service->soap_functions.ft == NULL) {
11531152
service->soap_functions.functions_all = FALSE;
@@ -1166,8 +1165,8 @@ PHP_METHOD(SoapServer, addFunction)
11661165
}
11671166
service->soap_functions.functions_all = TRUE;
11681167
} else {
1169-
php_error_docref(NULL, E_WARNING, "Invalid value passed");
1170-
return;
1168+
zend_argument_value_error(1, "must be SOAP_FUNCTIONS_ALL when an integer is passed");
1169+
RETURN_THROWS();
11711170
}
11721171
}
11731172

@@ -1217,7 +1216,7 @@ PHP_METHOD(SoapServer, handle)
12171216
int old_features;
12181217
zval tmp_soap;
12191218

1220-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &arg, &arg_len) == FAILURE) {
1219+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!", &arg, &arg_len) == FAILURE) {
12211220
RETURN_THROWS();
12221221
}
12231222

@@ -1226,7 +1225,7 @@ PHP_METHOD(SoapServer, handle)
12261225
FETCH_THIS_SERVICE(service);
12271226
SOAP_GLOBAL(soap_version) = service->version;
12281227

1229-
if (ZEND_NUM_ARGS() > 0 && ZEND_SIZE_T_INT_OVFL(arg_len)) {
1228+
if (arg && ZEND_SIZE_T_INT_OVFL(arg_len)) {
12301229
soap_server_fault("Server", "Input string is too long", NULL, NULL, NULL);
12311230
return;
12321231
}
@@ -1281,7 +1280,7 @@ PHP_METHOD(SoapServer, handle)
12811280
php_error_docref(NULL, E_ERROR,"ob_start failed");
12821281
}
12831282

1284-
if (ZEND_NUM_ARGS() == 0) {
1283+
if (!arg) {
12851284
if (SG(request_info).request_body && 0 == php_stream_rewind(SG(request_info).request_body)) {
12861285
zval *server_vars, *encoding;
12871286
php_stream_filter *zf = NULL;
@@ -1741,8 +1740,8 @@ PHP_METHOD(SoapServer, addSoapHeader)
17411740
FETCH_THIS_SERVICE(service);
17421741

17431742
if (!service || !service->soap_headers_ptr) {
1744-
php_error_docref(NULL, E_WARNING, "The SoapServer::addSoapHeader function may be called only during SOAP request processing");
1745-
return;
1743+
zend_throw_error(NULL, "SoapServer::addSoapHeader() may be called only during SOAP request processing");
1744+
RETURN_THROWS();
17461745
}
17471746

17481747
p = service->soap_headers_ptr;
@@ -2567,9 +2566,9 @@ void soap_client_call_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_soap_call)
25672566
zend_hash_next_index_insert(soap_headers, headers);
25682567
Z_ADDREF_P(headers);
25692568
free_soap_headers = 1;
2570-
} else{
2571-
php_error_docref(NULL, E_WARNING, "Invalid SOAP header");
2572-
return;
2569+
} else {
2570+
zend_argument_type_error(4, "must be of type SoapHeader|array|null, %s given", zend_zval_type_name(headers));
2571+
RETURN_THROWS();
25732572
}
25742573

25752574
/* Add default headers */
@@ -2875,8 +2874,9 @@ PHP_METHOD(SoapClient, __setSoapHeaders)
28752874
add_next_index_zval(&default_headers, headers);
28762875
add_property_zval(this_ptr, "__default_headers", &default_headers);
28772876
Z_DELREF_P(&default_headers);
2878-
} else{
2879-
php_error_docref(NULL, E_WARNING, "Invalid SOAP header");
2877+
} else {
2878+
zend_argument_type_error(1, "must be of type SoapHeader|array|null, %s given", zend_zval_type_name(headers));
2879+
RETURN_THROWS();
28802880
}
28812881
RETURN_TRUE;
28822882
}

ext/soap/soap.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function getFunctions() {}
5757
public function addFunction($functions) {}
5858

5959
/** @return void */
60-
public function handle(string $soap_request = UNKNOWN) {}
60+
public function handle(?string $soap_request = null) {}
6161
}
6262

6363
class SoapClient

ext/soap/soap_arginfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 75e1f968f03aacc08ad7858adff05040ed61e23d */
2+
* Stub hash: b33d57ddba20c64739d51bfba39f2557026939cd */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_use_soap_error_handler, 0, 0, _IS_BOOL, 0)
55
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, handler, _IS_BOOL, 0, "true")
@@ -81,7 +81,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SoapServer_addFunction, 0, 0, 1)
8181
ZEND_END_ARG_INFO()
8282

8383
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SoapServer_handle, 0, 0, 0)
84-
ZEND_ARG_TYPE_INFO(0, soap_request, IS_STRING, 0)
84+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, soap_request, IS_STRING, 1, "null")
8585
ZEND_END_ARG_INFO()
8686

8787
#define arginfo_class_SoapClient___construct arginfo_class_SoapServer___construct

ext/soap/tests/bugs/bug31755.phpt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@ Bug #31422 (No Error-Logging on SoapServer-Side)
77
$client=new SOAPClient(null, array('location' => 'http://localhost',
88
'uri' => 'myNS', 'exceptions' => false, 'trace' => true));
99

10-
$header = new SOAPHeader(null, 'foo', 'bar');
10+
try {
11+
new SOAPHeader('', 'foo', 'bar');
12+
} catch (ValueError $exception) {
13+
echo $exception->getMessage() . "\n";
14+
}
1115

16+
$header = new SOAPHeader('namespace', 'foo', 'bar');
1217
$response= $client->__soapCall('function', array(), null, $header);
1318

1419
print $client->__getLastRequest();
1520
?>
16-
--EXPECTF--
17-
Warning: SoapHeader::__construct(): Invalid namespace in %s on line %d
21+
--EXPECT--
22+
SoapHeader::__construct(): Argument #1 ($namespace) cannot be empty
1823
<?xml version="1.0" encoding="UTF-8"?>
19-
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="myNS" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Header/><SOAP-ENV:Body><ns1:function/></SOAP-ENV:Body></SOAP-ENV:Envelope>
24+
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="myNS" xmlns:ns2="namespace" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Header><ns2:foo>bar</ns2:foo></SOAP-ENV:Header><SOAP-ENV:Body><ns1:function/></SOAP-ENV:Body></SOAP-ENV:Envelope>

ext/soap/tests/fault_warning.phpt

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ SoapFault class: Invalid Fault code warning given? Can't be an empty string, an
44
<?php require_once('skipif.inc'); ?>
55
--FILE--
66
<?php
7-
$fault = new SoapFault("", "message"); // Can't be an empty string
7+
8+
try {
9+
new SoapFault("", "message"); // Can't be an empty string
10+
} catch (ValueError $exception) {
11+
echo $exception->getMessage() . "\n";
12+
}
813

914
try {
1015
new SoapFault(new stdClass(), "message"); // Can't be a non-string (except for null)
@@ -16,18 +21,28 @@ $fault = new SoapFault("Sender", "message");
1621
echo get_class($fault) . "\n";
1722
$fault = new SoapFault(null, "message");
1823
echo get_class($fault) . "\n";
19-
$fault = new SoapFault(["more"], "message"); // two elements in array required
20-
$fault = new SoapFault(["m", "more", "superfluous"], "message"); // two required
24+
25+
try {
26+
new SoapFault(["more"], "message"); // two elements in array required
27+
} catch (ValueError $exception) {
28+
echo $exception->getMessage() . "\n";
29+
}
30+
31+
try {
32+
new SoapFault(["m", "more", "superfluous"], "message"); // two required
33+
} catch (ValueError $exception) {
34+
echo $exception->getMessage() . "\n";
35+
}
36+
2137
$fault = new SoapFault(["more-ns", "Sender"], "message"); // two given
2238
echo get_class($fault);
39+
2340
?>
24-
--EXPECTF--
25-
Warning: SoapFault::__construct(): Invalid fault code in %s on line %d
41+
--EXPECT--
42+
SoapFault::__construct(): Argument #1 ($faultcode) is not a valid fault code
2643
SoapFault::__construct(): Argument #1 ($faultcode) must be of type string|array|null, stdClass given
2744
SoapFault
2845
SoapFault
29-
30-
Warning: SoapFault::__construct(): Invalid fault code in %s on line %d
31-
32-
Warning: SoapFault::__construct(): Invalid fault code in %s on line %d
46+
SoapFault::__construct(): Argument #1 ($faultcode) is not a valid fault code
47+
SoapFault::__construct(): Argument #1 ($faultcode) is not a valid fault code
3348
SoapFault

ext/xmlwriter/php_xmlwriter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -896,8 +896,8 @@ PHP_FUNCTION(xmlwriter_open_uri)
896896
}
897897

898898
if (source_len == 0) {
899-
php_error_docref(NULL, E_WARNING, "Empty string as source");
900-
RETURN_FALSE;
899+
zend_argument_value_error(1, "cannot be empty");
900+
RETURN_THROWS();
901901
}
902902

903903
valid_file = _xmlwriter_get_valid_file_path(source, resolved_path, MAXPATHLEN);

ext/xmlwriter/tests/xmlwriter_open_uri_error_001.phpt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ xmlwriter_open_uri with empty string as parameter
44
<?php if (!extension_loaded("xmlwriter")) print "skip"; ?>
55
--FILE--
66
<?php
7-
var_dump(xmlwriter_open_uri(''));
7+
try {
8+
xmlwriter_open_uri('');
9+
} catch (ValueError $exception) {
10+
echo $exception->getMessage() . "\n";
11+
}
812
?>
913
--CREDITS--
1014
Koen Kuipers [email protected]
1115
Theo van der Zee
1216
#Test Fest Utrecht 09-05-2009
13-
--EXPECTF--
14-
Warning: xmlwriter_open_uri(): Empty string as source in %s on line %d
15-
bool(false)
17+
--EXPECT--
18+
xmlwriter_open_uri(): Argument #1 ($uri) cannot be empty

0 commit comments

Comments
 (0)