Skip to content

Commit e50f18b

Browse files
committed
Improve and simplify exceptions
1 parent 78035c0 commit e50f18b

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

Zend/zend_string.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,6 @@ EMPTY_SWITCH_DEFAULT_CASE()
597597
_(ZEND_STR_HOST, "host") \
598598
_(ZEND_STR_PORT, "port") \
599599
_(ZEND_STR_USER, "user") \
600-
_(ZEND_STR_USERINFO, "userinfo") \
601600
_(ZEND_STR_USERNAME, "username") \
602601
_(ZEND_STR_PASS, "pass") \
603602
_(ZEND_STR_PASSWORD, "password") \

build/gen_stub.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3055,7 +3055,6 @@ class PropertyInfo extends VariableLike
30553055
private const PHP_85_KNOWN = [
30563056
"self" => "ZEND_STR_SELF",
30573057
"parent" => "ZEND_STR_PARENT",
3058-
"userinfo" => "ZEND_STR_USERINFO",
30593058
"username" => "ZEND_STR_USERNAME",
30603059
"password" => "ZEND_STR_PASSWORD",
30613060
];

ext/uri/php_uri.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,7 @@ static void read_uriparser_userinfo(INTERNAL_FUNCTION_PARAMETERS, uri_component_
312312
URI_ASSERT_INITIALIZATION(internal_uri);
313313

314314
if (UNEXPECTED(uriparser_read_userinfo(internal_uri, read_mode, return_value) == FAILURE)) {
315-
zend_throw_error(NULL, "%s::$%s property cannot be retrieved", ZSTR_VAL(Z_OBJ_P(ZEND_THIS)->ce->name),
316-
ZSTR_VAL(ZSTR_KNOWN(ZEND_STR_USERINFO)));
315+
zend_throw_error(NULL, "The userinfo component cannot be retrieved");
317316
RETURN_THROWS();
318317
}
319318
}
@@ -393,6 +392,11 @@ PHP_METHOD(Uri_Rfc3986_Uri, getRawFragment)
393392
uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_FRAGMENT, URI_COMPONENT_READ_RAW);
394393
}
395394

395+
static void throw_cannot_recompose_uri_to_string(zend_object *object)
396+
{
397+
zend_throw_exception_ex(NULL, 0, "Cannot recompose %s to a string", ZSTR_VAL(object->ce->name));
398+
}
399+
396400
static void uri_equals(INTERNAL_FUNCTION_PARAMETERS, zend_object *that_object, zend_object *comparison_mode)
397401
{
398402
zend_object *this_object = Z_OBJ_P(ZEND_THIS);
@@ -418,15 +422,15 @@ static void uri_equals(INTERNAL_FUNCTION_PARAMETERS, zend_object *that_object, z
418422
zend_string *this_str = this_internal_uri->handler->uri_to_string(
419423
this_internal_uri->uri, URI_RECOMPOSITION_NORMALIZED_ASCII, exclude_fragment);
420424
if (this_str == NULL) {
421-
zend_throw_exception_ex(NULL, 0, "Cannot recompose %s to string", ZSTR_VAL(this_object->ce->name));
425+
throw_cannot_recompose_uri_to_string(this_object);
422426
RETURN_THROWS();
423427
}
424428

425429
zend_string *that_str = that_internal_uri->handler->uri_to_string(
426430
that_internal_uri->uri, URI_RECOMPOSITION_NORMALIZED_ASCII, exclude_fragment);
427431
if (that_str == NULL) {
428432
zend_string_release(this_str);
429-
zend_throw_exception_ex(NULL, 0, "Cannot recompose %s to string", ZSTR_VAL(that_object->ce->name));
433+
throw_cannot_recompose_uri_to_string(that_object);
430434
RETURN_THROWS();
431435
}
432436

@@ -460,7 +464,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, toRawString)
460464

461465
zend_string *uri_str = internal_uri->handler->uri_to_string(internal_uri->uri, URI_RECOMPOSITION_RAW_ASCII, false);
462466
if (uri_str == NULL) {
463-
zend_throw_exception_ex(NULL, 0, "Cannot recompose %s to string", ZSTR_VAL(this_object->ce->name));
467+
throw_cannot_recompose_uri_to_string(this_object);
464468
RETURN_THROWS();
465469
}
466470

@@ -477,7 +481,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, toString)
477481

478482
zend_string *uri_str = internal_uri->handler->uri_to_string(internal_uri->uri, URI_RECOMPOSITION_NORMALIZED_ASCII, false);
479483
if (uri_str == NULL) {
480-
zend_throw_exception_ex(NULL, 0, "Cannot recompose %s to string", ZSTR_VAL(this_object->ce->name));
484+
throw_cannot_recompose_uri_to_string(this_object);
481485
RETURN_THROWS();
482486
}
483487

@@ -510,7 +514,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, __serialize)
510514
/* Serialize state: "uri" key in the first array */
511515
zend_string *uri_str = internal_uri->handler->uri_to_string(internal_uri->uri, URI_RECOMPOSITION_RAW_ASCII, false);
512516
if (uri_str == NULL) {
513-
zend_throw_exception_ex(NULL, 0, "Cannot recompose %s to string", ZSTR_VAL(this_object->ce->name));
517+
throw_cannot_recompose_uri_to_string(this_object);
514518
RETURN_THROWS();
515519
}
516520
zval tmp;
@@ -723,7 +727,7 @@ PHP_METHOD(Uri_WhatWg_Url, __serialize)
723727
/* Serialize state: "uri" key in the first array */
724728
zend_string *uri_str = internal_uri->handler->uri_to_string(internal_uri->uri, URI_RECOMPOSITION_RAW_ASCII, false);
725729
if (uri_str == NULL) {
726-
zend_throw_exception_ex(NULL, 0, "Cannot recompose %s to string", ZSTR_VAL(this_object->ce->name));
730+
throw_cannot_recompose_uri_to_string(this_object);
727731
RETURN_THROWS();
728732
}
729733
zval tmp;

ext/uri/php_uri_common.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ void uri_read_component(INTERNAL_FUNCTION_PARAMETERS, uri_property_name_t proper
7676
ZEND_ASSERT(property_handler != NULL);
7777

7878
if (UNEXPECTED(property_handler->read_func(internal_uri, component_read_mode, return_value) == FAILURE)) {
79-
zend_throw_error(NULL, "%s::$%s property cannot be retrieved", ZSTR_VAL(Z_OBJ_P(ZEND_THIS)->ce->name),
80-
ZSTR_VAL(get_known_string_by_property_name(property_name)));
79+
zend_throw_error(NULL, "The %s component cannot be retrieved", ZSTR_VAL(get_known_string_by_property_name(property_name)));
8180
RETURN_THROWS();
8281
}
8382
}

0 commit comments

Comments
 (0)