Skip to content

Deprecate passing null to non-nullable arg of internal function #4227

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 4 commits into from

Conversation

nikic
Copy link
Member

@nikic nikic commented Jun 5, 2019

For user functions, parameters only accept null if they are explicitly declared nullable -- independently of strict_types. An int parameter will always reject null. It is necessary to use ?int to accept it.

The same is not the case for internal functions using zpp, which will silently accept null and cast it to the appropriate type (will become one of false, 0, 0.0 or ""). If the internal function uses arginfo instead, then the behavior is the same as for user functions.

As we would like to annotate internal functions with arginfo information in PHP 8, it is important to resolve this behavioral difference -- otherwise any future arginfo addition may also result in a behavior change wrt null handling. Edit: This particular issue has been resolved by special-casing arginfo handling for internal functions.

TODO:

  • Finish test updates

@nikic nikic added the RFC label Jun 5, 2019
php-pulls pushed a commit that referenced this pull request Jun 5, 2019
It should be possible to skip any of these (and use the ini configured
defaults) by passing null, independently of strict_types settings.

Noticed while working on GH-4227.
nikic added 4 commits June 5, 2019 11:30
The ones where bless_tests.php worked right with little modification.
@nikic
Copy link
Member Author

nikic commented Feb 5, 2020

The ship has sailed here for 7.4, but might be worth considering again for PHP 8.

Before we do so, we'll need to do some comprehensive review of internal function parameters that should be nullable but aren't. People who have been adding stubs (cc @kocsismate) have probably noticed that we have a lot of string $param = UNKNOWN cases, where there is no well-defined default value, but the parameter isn't nullable either.

Ideally we'd change those to be nullable (even independently of the change proposed here).

@kocsismate
Copy link
Member

I also planned to ask you in the recent days if it is feasible to sneak this into PHP 7.4. Yes, it would be a breaking change for sure, but it could still be very useful for forward-compatibility. Unfortunately, I am not sure if PHP has precedents to do something like this before...

But surely, getting rid of UNKNOWN default values would be a really good next step. I'll definitely add this to my to-do list.

@nikic
Copy link
Member Author

nikic commented Feb 5, 2020

I also planned to ask you in the recent days if it is feasible to sneak this into PHP 7.4. Yes, it would be a breaking change for sure, but it could still be very useful for forward-compatibility. Unfortunately, I am not sure if PHP has precedents to do something like this before...

I don't think we really do deprecations in patch releases ... but as this particular one if very large and has a lot of potential impact, it definitely can't go into 7.4.

@kocsismate
Copy link
Member

I don't think we really do deprecations in patch releases

Yes, I can't remember any... :/

this particular one if very large and has a lot of potential impact

Ah yes, makes sense... I have to remember myself that breaking backward compatibility (at such a big scale) isn't worth for forward compatibility...

@nikic
Copy link
Member Author

nikic commented Dec 1, 2020

This PR is rebooted at #6475.

@nikic nikic closed this Dec 1, 2020
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