Skip to content

Implement Query Parameter Manipulation Support RFC - #22551

Draft
kocsismate wants to merge 2 commits into
php:masterfrom
kocsismate:query-params
Draft

kocsismate wants to merge 2 commits into
php:masterfrom
kocsismate:query-params

Conversation

@kocsismate

@kocsismate kocsismate commented Jul 2, 2026 •

Copy link
Copy Markdown
Member

@kocsismate
kocsismate requested a review from ndossche July 2, 2026 12:17
@kocsismate
kocsismate requested a review from TimWolla as a code owner July 2, 2026 12:17
@kocsismate
kocsismate marked this pull request as draft July 2, 2026 12:18
@kocsismate kocsismate changed the title Implement Qquery Parameter Manipulation Support RFC Implement Query Parameter Manipulation Support RFC Jul 2, 2026

@TimWolla TimWolla left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments without trying to understand the logic.

Comment on lines +697 to +700
zend_string *result = zend_string_alloc(str_length, false);

memcpy(ZSTR_VAL(result), str, str_length);
ZSTR_VAL(result)[str_length] = '\0';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can also just be zend_string_init().

}

if (UNEXPECTED(str_length == 0)) {
return zend_empty_string;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ZSTR_EMPTY_ALLOC

}
} ZEND_HASH_FOREACH_END();

return buf.s != NULL ? smart_str_extract(&buf) : ZSTR_EMPTY_ALLOC();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This optimization is handled automatically:

if (str->s) {
zend_string *res;
smart_str_0(str);
smart_str_trim_to_size_ex(str, persistent);
res = str->s;
str->s = NULL;
return res;
} else {
return ZSTR_EMPTY_ALLOC();
}

Comment thread ext/uri/php_uri_query.c Outdated
options->parsing_max_param_count = parsing_max_param_count;

if (true_value == NULL) {
options->true_value = zend_string_init(ZEND_STRL("1"), false);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ZSTR_CHAR

Comment thread ext/uri/php_uri_query.c Outdated
Comment on lines +55 to +59
if (true_value == NULL) {
options->true_value = zend_string_init(ZEND_STRL("1"), false);
} else {
options->true_value = true_value;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel this is more readable.

Suggested change
if (true_value == NULL) {
options->true_value = zend_string_init(ZEND_STRL("1"), false);
} else {
options->true_value = true_value;
}
if (true_value == NULL) {
true_value = ZSTR_CHAR('1');
}
options->true_value = true_value;

Comment thread ext/uri/php_uri_query.c Outdated
case IS_RESOURCE:
zend_argument_value_error(2, "must not contain a resource");
return NULL;
case IS_ARRAY: {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very inconsistent use of braces. They are not needed in the majority of cases.

Comment thread ext/uri/php_uri_query.c Outdated
return NULL;
}
case IS_OBJECT:
if (Z_OBJCE_P(zv)->ce_flags & ZEND_ACC_ENUM && Z_OBJCE_P(zv)->enum_backing_type != IS_UNDEF) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (Z_OBJCE_P(zv)->ce_flags & ZEND_ACC_ENUM && Z_OBJCE_P(zv)->enum_backing_type != IS_UNDEF) {
if ((Z_OBJCE_P(zv)->ce_flags & ZEND_ACC_ENUM) && Z_OBJCE_P(zv)->enum_backing_type != IS_UNDEF) {

Comment thread ext/uri/php_uri_query.c

if (
(value == NULL && list_entry->value == NULL) ||
(value != NULL && list_entry->value != NULL && zend_string_equal_content(value, list_entry->value))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this isn't just?

Suggested change
(value != NULL && list_entry->value != NULL && zend_string_equal_content(value, list_entry->value))
(value != NULL && list_entry->value != NULL && zend_string_equal(value, list_entry->value))

Comment thread ext/uri/php_uri_query.c
return NULL;
}

php_uri_query_params_iterator *iterator = emalloc(sizeof(php_uri_query_params_iterator));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
php_uri_query_params_iterator *iterator = emalloc(sizeof(php_uri_query_params_iterator));
php_uri_query_params_iterator *iterator = emalloc(sizeof(*iterator));

@kocsismate
kocsismate force-pushed the query-params branch 2 times, most recently from 5ca5451 to ee775db Compare November 20, 2026 15:01
}
} ZEND_HASH_FOREACH_END();

return buf.s != NULL ? smart_str_extract(&buf) : ZSTR_EMPTY_ALLOC();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smart_str_extract handles this optimization by itself.

return NULL;
}

if (is_first) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can check smart_str_get_len() > 0 to avoid the extra variable.

}
}

ZSTR_LEN(result) = (size_t)(end - ZSTR_VAL(result));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a fishy cast.

Comment thread ext/uri/php_uri_query.c
return zend_string_init(buffer, strlen(buffer), false);
}
case IS_OBJECT:
if (instanceof_function(Z_OBJCE_P(value), zend_ce_backed_enum)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instanceof is needlessly expensive. Borrow the checks from zend_enum_fetch_case_value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants