Skip to content

Zend: refactor zend_parse_arg_impl() to return zend_expected_type - #23052

Open
Girgias wants to merge 1 commit into
php:masterfrom
Girgias:2026-08-old-zpp-use-error-msg
Open

Zend: refactor zend_parse_arg_impl() to return zend_expected_type#23052
Girgias wants to merge 1 commit into
php:masterfrom
Girgias:2026-08-old-zpp-use-error-msg

Conversation

@Girgias

@Girgias Girgias commented Aug 4, 2026

Copy link
Copy Markdown
Member

This effectively mimics part of what Fast ZPP does and allows us to re-use the fast ZPP error APIs

Further refactorings: #23104 and #23105.

Comment thread Zend/zend_API.c Outdated
This effectively mimics part of what Fast ZPP does and allows us to re-use the fast ZPP error APIs
@Girgias
Girgias force-pushed the 2026-08-old-zpp-use-error-msg branch from 3ccd8f2 to 750ff30 Compare August 7, 2026 18:57
Comment thread Zend/zend_API.c
Comment on lines -911 to -916
if (Z_TYPE_P(arg) == IS_STRING) {
zend_spprintf(error, 0, "must not contain any null bytes");
return "";
} else {
return check_null ? "?string" : "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.

Do I understand correct that this was just so that the user is informed about NUL bytes in their path string? Because the NUL bytes are already handled in zend_str_has_nul_byte but the error message would be generic, right? Now, you handle it with zend_wrong_parameter_type_error.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes. This is the purpose of this ZPP specifier, and has always been this way.

You get the same error message either way, fast ZPP only uses zend_wrong_parameter_type_error to generate error messages.

@kamil-tekiela kamil-tekiela Aug 7, 2026

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.

Ok, but one thing I don't understand. Previously if (Z_TYPE_P(arg) == IS_STRING) { was after ZVAL_DEREF(arg) but now in the zend_wrong_parameter_type_error, you have this check but I cannot find any ZVAL_DEREF(arg) up the call stack. Am I missing something?

Do we have a unit test for something like this:

$s = "abc\0def";
$ref = &$s;
fopen($ref, 'r'); 

EDIT: So I asked Claude to explain this to me and it told me that it's not possible for zend_parse_arg/zend_parse_arg_impl to receive a reference, so there is no need for dereference checks. I can't say that I understand why it's in one place and not in the other, but at least it doesn't cause a regression.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not interested in a "review" from Claude.

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.

Just to clarify, to avoid any misunderstanding, the review is mine. I only used Claude to help me understand the code. I am genuinely asking why we have ZVAL_DEREF(arg) but not in the other place.

@kamil-tekiela

kamil-tekiela commented Aug 7, 2026

Copy link
Copy Markdown
Member
<?php
declare(strict_types=1);
get_class_vars(123);

This will throw a different message now, correct? We don't seem to have a test for this. With declare(strict_types=1)

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