-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[PropertyInfo] Fix typed collections in PHP 7.4 #38041
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
Conversation
Travis is failing on FrameworkBundle tests, it appears to be unrelated to this PR as the same test failures are present in a number of other open PRs. If my PR has somehow affected these tests I'm happy to fix them if someone can point in the right direction. Test failures
|
/cc @ogizanagi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me appart from my comment perhaps. As I'm not the original author, I may miss something, though.
Thank you for the PR!
@@ -170,6 +158,18 @@ public function getTypes($class, $property, array $context = []): ?array | |||
return $fromDefaultValue; | |||
} | |||
|
|||
if (\PHP_VERSION_ID >= 70400) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'll make more sense to have precedence over constructor and default value extraction (the two if
above), right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ogizanagi yeah it might make more sense in the fact that if there is constructor args or default values as well as a php7.4 property type it might be more simple to just extract from the property type? I'm not sure it makes much of a difference though. Happy to move it if you like?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I slightly prefer like this (regarding the comment)
Thank you @ndench. |
#37971 introduced support for typed properties in PHP 7.4, however by short circuiting the
getTypes()
method, typed collections are returned asType::BUILTIN_TYPE_ARRAY
without a proper collection type. If running on PHP < 7.4, thegetMutator()
method would be called which would extract the collection type from the getter/setter or adder/remover.I updated the typedPropertiesTest to cover this case.