Skip to content

Make zpp failures always throw, independent of strict_types #3794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 53 commits into from

Conversation

nikic
Copy link
Member

@nikic nikic commented Feb 5, 2019

RFC: https://wiki.php.net/rfc/consistent_type_errors

Previously zend_parse_parameters (and FastZPP) would handle invalid
arguments depending on strict_types: With strict_types=1, a TypeError
is thrown, with strict_types=0 a warning is thrown and (usually) NULL
is returned. Additionally, some functions (constructors always and
other methods sometimes) opt-it to throwing regardless of strict_types.

This patch changes zpp to always generate an Error exception in
PHP 8.

Even with some of the zpp variation tests removed in #3783, this is
going to need a lot of test updates, as many tests are also testing
zpp failures. I haven't really started on this yet.

@nikic nikic added the RFC label Feb 5, 2019
@nikic nikic added this to the PHP 8.0 milestone Feb 5, 2019

/* Parameter parsing API -- andrei */

#define ZEND_PARSE_PARAMS_THROW 0 /* No longer used, zpp always uses exceptions */
Copy link
Member

Choose a reason for hiding this comment

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

I think you should remove this define, so that it is more apparent that if this is used, the code no longer functions according to the intention.

Copy link
Member Author

Choose a reason for hiding this comment

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

It still works as intended though -- it's just no longer necessary to specify it explicitly. I think especially in conjunction with zend_parse_parameters_throw and ZEND_PARSE_PARAMS_THROW, it would be best to preserve these functions/macros, so as to avoid unnecessary churn for extensions that already opt-in to throwing. Otherwise each extension will have to define these for compatibility.

@nikic nikic force-pushed the zpp-always-throws branch from e8de760 to 8258eee Compare February 19, 2019 16:26
@nikic nikic force-pushed the zpp-always-throws branch 6 times, most recently from 30bf210 to 8b7f213 Compare March 7, 2019 16:11
nikic added 20 commits March 8, 2019 13:47
Previously zend_parse_parameters (and FastZPP) would handle invalid
arguments depending on strict_types: With strict_types=1, a TypeError
is thrown, with strict_types=0 a warning is thrown and (usually) NULL
is returned. Additionally, some functions (constructors always and
other methods sometimes) opt-it to throwing regardless of strict_types.

This commit changes zpp to always generate an Error exception in
PHP 8.

Even with some of the zpp variation tests removed in php#3783, this is
going to need a lot of test updates, as many tests are also testing
zpp failures. I haven't really started on this yet.
zpp will be throwing for these now, don't report them in addition to
that.
The exception type is going to change from UnexpectedValueException
to TypeError here.
@nikic nikic force-pushed the zpp-always-throws branch from 8b7f213 to d001b6a Compare March 8, 2019 12:48
@nikic
Copy link
Member Author

nikic commented Mar 11, 2019

Merged as: 513b767, 86ef425, 6bfb119, 852485d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants