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

Better PHP8 type handling #918

Merged
merged 4 commits into from
Jan 20, 2021
Merged

Conversation

adambalint-srg
Copy link
Contributor

I've found two type declaration related problems in proxy generator, when using it with PHP8.

First is the usage of static keyword, which should be "copied" to the proxy class, and also can be nullable.
function setId(int $id): ?static
This is supported in this pull request.

Second is a fix for union types of PHP8, because in case of nullable union types the '?' sign is nut supported. It should be used in this way:
float|int|null
But the proxy generator prepended the '?' to the null part of the union type:
float|int|?null
This problem has been fixed with an optional argument in case of recursive call of formatType function.

In case of nullable union types, '?' sign is not supported. The current solution for uniont types (the recursive call) prepended the '?' sign to the null type, so I had to handle this with an additional option for the formatType method of the ProxyGenerator.
PHP8 supports 'static' keyword as a return type. This should be copied to the proxy class without any transformation. This type is not a "builtin" type in php, so I should extend some if branches with an additional condition so allow this new keyword.
With a name check it's more logical to check the null value, because this is the only one when the unnecessary '?' sign can occure. So no function parameter is required with this solution. Thanks @jellynoone
@jellynoone
Copy link

Can someone from the Doctrine team review the pull request? @beberlei @greg0ire

By now the author, myself and doctrine/orm#8422 have found the issue being solved in this pull request.

@greg0ire greg0ire added the Bug label Jan 18, 2021
@beberlei beberlei added this to the 3.0.4 milestone Jan 20, 2021
@beberlei
Copy link
Member

beberlei commented Jan 20, 2021

Does this target the 3.1.x branch for a specific reason? This is a bugfix for me and should target 3.0.x

Edit: Sorry, my mistake Github showed 3.0.3 as last release, but it was actually 3.1.0 already.

@beberlei beberlei modified the milestones: 3.0.4, 3.1.1 Jan 20, 2021
@beberlei beberlei merged commit 2afde5a into doctrine:3.1.x Jan 20, 2021
@adambalint-srg adambalint-srg deleted the php8-types branch January 20, 2021 20:34
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.

None yet

5 participants