Skip to content
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

[PropertyInfo] Make ReflectionExtractor compatible with ReflectionType changes in PHP 7.1 #19853

Merged
merged 1 commit into from Sep 14, 2016

Conversation

teohhanhui
Copy link
Contributor

Q A
Branch? 2.8
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #19677 (comment)
License MIT
Doc PR N/A

@@ -231,7 +231,7 @@ private function extractFromAccessor($class, $property)
*/
private function extractFromReflectionType(\ReflectionType $reflectionType)
{
$phpTypeOrClass = (string) $reflectionType;
$phpTypeOrClass = method_exists($reflectionType, 'getName') ? $reflectionType->getName() : (string) $reflectionType;
Copy link
Member

Choose a reason for hiding this comment

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

Why this change?

Copy link
Contributor

Choose a reason for hiding this comment

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

\ReflectionType does't have a getName() method according to the docs: http://php.net/manual/en/class.reflectiontype.php. Will this be added in the future perhaps?

Copy link
Contributor Author

@teohhanhui teohhanhui Sep 5, 2016

Choose a reason for hiding this comment

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

@because ReflectionType::__toString has changed in PHP 7.1 and will change in the future (it is not properly part of the BC promise). As advised in the PHP 7.1 UPGRADING file, we need to use ReflectionNamedType::getName going forward.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@iltar

ReflectionType::__toString() will now return the type name with a leading
"?" if it is nullable. To retrieve the type name without leading "?" the new
ReflectionNamedType::getName() method can be used.

https://github.com/php/php-src/blob/9650b8e2412a919df8c5c626a1def937bc6d77d5/UPGRADING#L127-L129

Copy link
Contributor

@linaori linaori Sep 5, 2016

Choose a reason for hiding this comment

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

In case of the toString, shouldn't the ? be stripped?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If there is a getName method, then we won't be using __toString, and if we are using __toString that means it's PHP <= 7.0 so there is no ? prepended anyway. Stripping of characters is only a temporary solution anyway, as the __toString is likely to keep changing, judging from the mailing list discussion.

@dunglas
Copy link
Member

dunglas commented Sep 5, 2016

Fabbot error is a false positive (it doesn't support PHP 7.1 yet).

👍 but I propose to wait and see what happens to this feature before the release of 7.1 to merge the PR.

@teohhanhui
Copy link
Contributor Author

If we want people to test Symfony with PHP 7.1, we should provide the compatibility. It's already in RC now, so things shouldn't change as much.

@nicolas-grekas
Copy link
Member

@teohhanhui see #19817 and related failure

@fabpot
Copy link
Member

fabpot commented Sep 14, 2016

Thank you @teohhanhui.

@fabpot fabpot merged commit 4a041e9 into symfony:2.8 Sep 14, 2016
fabpot added a commit that referenced this pull request Sep 14, 2016
…flectionType changes in PHP 7.1 (teohhanhui)

This PR was merged into the 2.8 branch.

Discussion
----------

[PropertyInfo] Make ReflectionExtractor compatible with ReflectionType changes in PHP 7.1

| Q             | A
| ------------- | ---
| Branch?       | 2.8
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #19677 (comment)
| License       | MIT
| Doc PR        | N/A

Commits
-------

4a041e9 Make ReflectionExtractor compatible with ReflectionType changes in PHP 7.1
This was referenced Oct 3, 2016
@teohhanhui teohhanhui deleted the reflectiontype_7.1 branch March 12, 2019 14:24
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.

None yet

6 participants