Skip to content

[HttpKernel] Fix nullable types handling #20152

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

Merged
merged 1 commit into from
Oct 4, 2016

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Oct 4, 2016

Q A
Branch? 3.1
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #19784
License MIT
Doc PR -

@nicolas-grekas nicolas-grekas changed the title [HttpKernel][PropertyInfo] Fix HHVM/PHP7.1 compat [HttpKernel][PropertyInfo] Fix nullable types handling Oct 4, 2016
@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented Oct 4, 2016

The current code builds on top of a non existing semantical difference between isNullable and allowsNull. The engine has only one single state for these concepts. As such, we can't build something reliable on side effects of the new notation for nullable types as introduced in PHP 7.1. See e.g. this comment on the topic.
This PR makes both concepts collapse into a single one.

@nicolas-grekas
Copy link
Member Author

Fixes the current failures on 3.1 for HHVM.
Ping @iltar FYI

@@ -27,7 +27,7 @@
*/
public function supports(Request $request, ArgumentMetadata $argument)
{
return $argument->hasDefaultValue() || $argument->isNullable();
return $argument->hasDefaultValue() || ($argument->isNullable() && !$argument->isVariadic());
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think variadic works here either way (php 7.0 and 7.1):

php > function (...$foo = []) {};
PHP Fatal error:  Variadic parameter cannot have a default value in php shell code on line 1

Copy link
Member Author

@nicolas-grekas nicolas-grekas Oct 4, 2016

Choose a reason for hiding this comment

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

but variadics allow null: function foo(...$bar) {}; => foo(null) is allowed, that's the point here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah the previous case wouldn't even reach here, fair enough

@nicolas-grekas nicolas-grekas changed the title [HttpKernel][PropertyInfo] Fix nullable types handling [HttpKernel] Fix nullable types handling Oct 4, 2016
@fabpot
Copy link
Member

fabpot commented Oct 4, 2016

Thank you @nicolas-grekas.

@fabpot fabpot merged commit 0884518 into symfony:3.1 Oct 4, 2016
fabpot added a commit that referenced this pull request Oct 4, 2016
This PR was merged into the 3.1 branch.

Discussion
----------

[HttpKernel] Fix nullable types handling

| Q             | A
| ------------- | ---
| Branch?       | 3.1
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #19784
| License       | MIT
| Doc PR        | -

Commits
-------

0884518 [HttpKernel] Fix nullable types handling
@nicolas-grekas nicolas-grekas deleted the php71-fix branch October 5, 2016 08:16
@fabpot fabpot mentioned this pull request Oct 27, 2016
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.

4 participants