Skip to content

Commit e03c2f9

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

File tree

5 files changed

+65
-61
lines changed

5 files changed

+65
-61
lines changed

ext/soap/soap.c

Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ 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(); \
154154
return; \
155155
} \
@@ -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(2, "is an invalid type ID");
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 invalid");
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();
@@ -993,32 +999,25 @@ PHP_METHOD(SoapServer, setClass)
993999
int num_args = 0;
9941000
zval *argv = NULL;
9951001

996-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S*", &classname, &argv, &num_args) == FAILURE) {
1002+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "C*", &ce, &argv, &num_args) == FAILURE) {
9971003
RETURN_THROWS();
9981004
}
9991005

10001006
SOAP_SERVER_BEGIN_CODE();
10011007

10021008
FETCH_THIS_SERVICE(service);
10031009

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

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-
}
1013+
service->soap_class.persistence = SOAP_PERSISTENCE_REQUEST;
1014+
service->soap_class.argc = num_args;
1015+
if (service->soap_class.argc > 0) {
1016+
int i;
1017+
service->soap_class.argv = safe_emalloc(sizeof(zval), service->soap_class.argc, 0);
1018+
for (i = 0;i < service->soap_class.argc;i++) {
1019+
ZVAL_COPY(&service->soap_class.argv[i], &argv[i]);
10181020
}
1019-
} else {
1020-
php_error_docref(NULL, E_WARNING, "Tried to set a non existent class (%s)", ZSTR_VAL(classname));
1021-
return;
10221021
}
10231022

10241023
SOAP_SERVER_END_CODE();
@@ -1122,14 +1121,15 @@ PHP_METHOD(SoapServer, addFunction)
11221121
zend_function *f;
11231122

11241123
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;
1124+
zend_argument_type_error(1, "must contain only strings");
1125+
RETURN_THROWS();
11271126
}
11281127

11291128
key = zend_string_tolower(Z_STR_P(tmp_function));
11301129

11311130
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));
1131+
zend_type_error(NULL, "SoapServer::addFunction(): Function \"%s\" not found", Z_STRVAL_P(tmp_function));
1132+
RETURN_THROWS();
11331133
return;
11341134
}
11351135

@@ -1146,8 +1146,8 @@ PHP_METHOD(SoapServer, addFunction)
11461146
key = zend_string_tolower(Z_STR_P(function_name));
11471147

11481148
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;
1149+
zend_argument_type_error(1, "must be a valid callback, function \"%s\" not found", Z_STRVAL_P(tmp_function));
1150+
RETURN_THROWS();
11511151
}
11521152
if (service->soap_functions.ft == NULL) {
11531153
service->soap_functions.functions_all = FALSE;
@@ -1166,8 +1166,8 @@ PHP_METHOD(SoapServer, addFunction)
11661166
}
11671167
service->soap_functions.functions_all = TRUE;
11681168
} else {
1169-
php_error_docref(NULL, E_WARNING, "Invalid value passed");
1170-
return;
1169+
zend_argument_value_error(1, "must be SOAP_FUNCTIONS_ALL when an integer is passed");
1170+
RETURN_THROWS();
11711171
}
11721172
}
11731173

@@ -1217,7 +1217,7 @@ PHP_METHOD(SoapServer, handle)
12171217
int old_features;
12181218
zval tmp_soap;
12191219

1220-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &arg, &arg_len) == FAILURE) {
1220+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!", &arg, &arg_len) == FAILURE) {
12211221
RETURN_THROWS();
12221222
}
12231223

@@ -1226,7 +1226,7 @@ PHP_METHOD(SoapServer, handle)
12261226
FETCH_THIS_SERVICE(service);
12271227
SOAP_GLOBAL(soap_version) = service->version;
12281228

1229-
if (ZEND_NUM_ARGS() > 0 && ZEND_SIZE_T_INT_OVFL(arg_len)) {
1229+
if (arg && ZEND_SIZE_T_INT_OVFL(arg_len)) {
12301230
soap_server_fault("Server", "Input string is too long", NULL, NULL, NULL);
12311231
return;
12321232
}
@@ -1281,7 +1281,7 @@ PHP_METHOD(SoapServer, handle)
12811281
php_error_docref(NULL, E_ERROR,"ob_start failed");
12821282
}
12831283

1284-
if (ZEND_NUM_ARGS() == 0) {
1284+
if (!arg) {
12851285
if (SG(request_info).request_body && 0 == php_stream_rewind(SG(request_info).request_body)) {
12861286
zval *server_vars, *encoding;
12871287
php_stream_filter *zf = NULL;
@@ -1741,8 +1741,8 @@ PHP_METHOD(SoapServer, addSoapHeader)
17411741
FETCH_THIS_SERVICE(service);
17421742

17431743
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;
1744+
zend_throw_error(NULL, "SoapServer::addSoapHeader() may be called only during SOAP request processing");
1745+
RETURN_THROWS();
17461746
}
17471747

17481748
p = service->soap_headers_ptr;
@@ -2567,9 +2567,9 @@ void soap_client_call_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_soap_call)
25672567
zend_hash_next_index_insert(soap_headers, headers);
25682568
Z_ADDREF_P(headers);
25692569
free_soap_headers = 1;
2570-
} else{
2571-
php_error_docref(NULL, E_WARNING, "Invalid SOAP header");
2572-
return;
2570+
} else {
2571+
zend_argument_type_error(4, "must be of type SoapHeader|array|null, %s given", zend_zval_type_name(headers));
2572+
RETURN_THROWS();
25732573
}
25742574

25752575
/* Add default headers */
@@ -2875,8 +2875,9 @@ PHP_METHOD(SoapClient, __setSoapHeaders)
28752875
add_next_index_zval(&default_headers, headers);
28762876
add_property_zval(this_ptr, "__default_headers", &default_headers);
28772877
Z_DELREF_P(&default_headers);
2878-
} else{
2879-
php_error_docref(NULL, E_WARNING, "Invalid SOAP header");
2878+
} else {
2879+
zend_argument_type_error(1, "must be of type SoapHeader|array|null, %s given", zend_zval_type_name(headers));
2880+
RETURN_THROWS();
28802881
}
28812882
RETURN_TRUE;
28822883
}

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/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)