Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Turn @return into real types on PHP 8 #40154

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
nicolas-grekas opened this issue Feb 11, 2021 · 5 comments
Closed

Turn @return into real types on PHP 8 #40154

nicolas-grekas opened this issue Feb 11, 2021 · 5 comments
Labels
Help wanted Issues and PRs which are looking for volunteers to complete them. Keep open

Comments

@nicolas-grekas
Copy link
Member

DebugClassCloader is already able to turn @return annotations into real return types.

We run it in the CI to ensure that type-declarations are in sync with the behavior of the code.

This can be reproduced locally by running:

composer i -o
SYMFONY_PATCH_TYPE_DECLARATIONS=force=1 php .github/patch-types.php

But this doesn't work on union types:

// ignore multi-types return declarations

CodeExtension::getFileLink is one example of a method that should be patched, but isn't right now.

I'm opening this PR to ask for help: this limitation should be removed when PHP 8 is used.

PR welcome :)

@nicolas-grekas nicolas-grekas added the Help wanted Issues and PRs which are looking for volunteers to complete them. label Feb 11, 2021
@stof
Copy link
Member

stof commented Feb 11, 2021

ideally, we would need to be able to turn that on based on a target PHP version which is not the current runtime. Otherwise, if your CI runs tests on both 7.4 and 8.0, a run on 8.0 would complain that you don't declare an actual return type somewhere, while declaring it would break support for PHP 7.4. We need to account for the min target version here.

@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented Feb 11, 2021

Actually, DebugClassLoader doesn't trigger a deprecation anymore as soon as the annotation is explicitly added to the method. We designed it this way to allow silencing the deprecation. So: adjusting the behavior based on the current runtime would be OK. Each line in the CI matrix would apply the return types it can understand.

Nyholm added a commit that referenced this issue Apr 8, 2021
This PR was merged into the 4.4 branch.

Discussion
----------

[PHPDoc] Fix some union type cases

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

While working on #40154, I discovered some PHPDoc issues, I'm going to comment in the review. Upper branches will need some fixes too.

Commits
-------

dd14816 [PHPDoc] Fix some union type cases
symfony-splitter pushed a commit to symfony/browser-kit that referenced this issue Apr 8, 2021
This PR was merged into the 4.4 branch.

Discussion
----------

[PHPDoc] Fix some union type cases

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

While working on symfony/symfony#40154, I discovered some PHPDoc issues, I'm going to comment in the review. Upper branches will need some fixes too.

Commits
-------

dd1481642b [PHPDoc] Fix some union type cases
symfony-splitter pushed a commit to symfony/security that referenced this issue Apr 8, 2021
This PR was merged into the 4.4 branch.

Discussion
----------

[PHPDoc] Fix some union type cases

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

While working on symfony/symfony#40154, I discovered some PHPDoc issues, I'm going to comment in the review. Upper branches will need some fixes too.

Commits
-------

dd1481642b [PHPDoc] Fix some union type cases
symfony-splitter pushed a commit to symfony/routing that referenced this issue Apr 8, 2021
This PR was merged into the 4.4 branch.

Discussion
----------

[PHPDoc] Fix some union type cases

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

While working on symfony/symfony#40154, I discovered some PHPDoc issues, I'm going to comment in the review. Upper branches will need some fixes too.

Commits
-------

dd1481642b [PHPDoc] Fix some union type cases
symfony-splitter pushed a commit to symfony/http-foundation that referenced this issue Apr 8, 2021
This PR was merged into the 4.4 branch.

Discussion
----------

[PHPDoc] Fix some union type cases

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

While working on symfony/symfony#40154, I discovered some PHPDoc issues, I'm going to comment in the review. Upper branches will need some fixes too.

Commits
-------

dd1481642b [PHPDoc] Fix some union type cases
symfony-splitter pushed a commit to symfony/validator that referenced this issue Apr 8, 2021
This PR was merged into the 4.4 branch.

Discussion
----------

[PHPDoc] Fix some union type cases

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

While working on symfony/symfony#40154, I discovered some PHPDoc issues, I'm going to comment in the review. Upper branches will need some fixes too.

Commits
-------

dd1481642b [PHPDoc] Fix some union type cases
symfony-splitter pushed a commit to symfony/serializer that referenced this issue Apr 8, 2021
This PR was merged into the 4.4 branch.

Discussion
----------

[PHPDoc] Fix some union type cases

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

While working on symfony/symfony#40154, I discovered some PHPDoc issues, I'm going to comment in the review. Upper branches will need some fixes too.

Commits
-------

dd1481642b [PHPDoc] Fix some union type cases
symfony-splitter pushed a commit to symfony/form that referenced this issue Apr 8, 2021
This PR was merged into the 4.4 branch.

Discussion
----------

[PHPDoc] Fix some union type cases

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

While working on symfony/symfony#40154, I discovered some PHPDoc issues, I'm going to comment in the review. Upper branches will need some fixes too.

Commits
-------

dd1481642b [PHPDoc] Fix some union type cases
symfony-splitter pushed a commit to symfony/messenger that referenced this issue Apr 8, 2021
This PR was merged into the 4.4 branch.

Discussion
----------

[PHPDoc] Fix some union type cases

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

While working on symfony/symfony#40154, I discovered some PHPDoc issues, I'm going to comment in the review. Upper branches will need some fixes too.

Commits
-------

dd1481642b [PHPDoc] Fix some union type cases
symfony-splitter pushed a commit to symfony/mailer that referenced this issue Apr 8, 2021
This PR was merged into the 4.4 branch.

Discussion
----------

[PHPDoc] Fix some union type cases

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

While working on symfony/symfony#40154, I discovered some PHPDoc issues, I'm going to comment in the review. Upper branches will need some fixes too.

Commits
-------

dd1481642b [PHPDoc] Fix some union type cases
symfony-splitter pushed a commit to symfony/security-core that referenced this issue Apr 8, 2021
This PR was merged into the 4.4 branch.

Discussion
----------

[PHPDoc] Fix some union type cases

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

While working on symfony/symfony#40154, I discovered some PHPDoc issues, I'm going to comment in the review. Upper branches will need some fixes too.

Commits
-------

dd1481642b [PHPDoc] Fix some union type cases
symfony-splitter pushed a commit to symfony/console that referenced this issue Apr 8, 2021
This PR was merged into the 4.4 branch.

Discussion
----------

[PHPDoc] Fix some union type cases

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

While working on symfony/symfony#40154, I discovered some PHPDoc issues, I'm going to comment in the review. Upper branches will need some fixes too.

Commits
-------

dd1481642b [PHPDoc] Fix some union type cases
@carsonbot
Copy link

Thank you for this issue.
There has not been a lot of activity here for a while. Has this been resolved?

@derrabus
Copy link
Member

We're still working on that, @carsonbot!

nicolas-grekas added a commit that referenced this issue Aug 13, 2021
This PR was merged into the 6.0 branch.

Discussion
----------

Add return types to bundles

| Q             | A
| ------------- | ---
| Branch?       | 6.0
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | #40154
| License       | MIT
| Doc PR        | -

Extracted from #42496

Bundles should be the safest to patch since their classes should be more rarely extended.

Commits
-------

89e3927 Add return types to bundles
nicolas-grekas added a commit that referenced this issue Aug 13, 2021
This PR was merged into the 6.0 branch.

Discussion
----------

Add return types to bridges

| Q             | A
| ------------- | ---
| Branch?       | 6.0
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | #40154
| License       | MIT
| Doc PR        | -

Extracted from #42496

Commits
-------

1ea501d Add return types to bridges
nicolas-grekas added a commit that referenced this issue Aug 13, 2021
This PR was merged into the 6.0 branch.

Discussion
----------

Add return types - batch 1/n

| Q             | A
| ------------- | ---
| Branch?       | 6.0
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | #40154
| License       | MIT
| Doc PR        | -

Extracted from #42496 for components that shouldn't be extended very often.

Commits
-------

1564887 Add return types - batch 1/n
nicolas-grekas added a commit that referenced this issue Aug 13, 2021
This PR was merged into the 6.0 branch.

Discussion
----------

Add return types - batch 2/n

| Q             | A
| ------------- | ---
| Branch?       | 6.0
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | #40154
| License       | MIT
| Doc PR        | -

Extracted from #42496 for components that shouldn't be extended very often.

Commits
-------

606775c Add return types - batch 2/n
nicolas-grekas added a commit that referenced this issue Aug 13, 2021
This PR was merged into the 6.0 branch.

Discussion
----------

Add return types - batch 3/n

| Q             | A
| ------------- | ---
| Branch?       | 6.0
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | #40154
| License       | MIT
| Doc PR        | -

Extracted from #42496 for components that shouldn't be extended very often.

Commits
-------

aef9069 Add return types - batch 3/n
nicolas-grekas added a commit that referenced this issue Aug 13, 2021
This PR was merged into the 6.0 branch.

Discussion
----------

Add return types - batch 4/n

| Q             | A
| ------------- | ---
| Branch?       | 6.0
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | #40154
| License       | MIT
| Doc PR        | -

Extracted from #42496

Not all possible return types are patched for the attached components, to save breaking BC cross-components, for now at least.

Commits
-------

bad9b7d Add return types - batch 4/n
nicolas-grekas added a commit that referenced this issue Aug 13, 2021
This PR was merged into the 6.0 branch.

Discussion
----------

Add return types - batch 5/n

| Q             | A
| ------------- | ---
| Branch?       | 6.0
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | #40154
| License       | MIT
| Doc PR        | -

Extracted from #42496

Not all possible return types are patched for the attached components, to save breaking BC cross-components, for now at least.

Commits
-------

00f08e4 Add return types - batch 5/n
nicolas-grekas added a commit that referenced this issue Aug 16, 2021
This PR was merged into the 6.0 branch.

Discussion
----------

Add return types - batch 6/n

| Q             | A
| ------------- | ---
| Branch?       | 6.0
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | #40154
| License       | MIT
| Doc PR        | -

Extracted from #42496

Not all possible return types are patched for the attached components, to save breaking BC cross-components, for now at least.

Commits
-------

df6b42e Add return types - batch 6/n
nicolas-grekas added a commit that referenced this issue Aug 19, 2021
This PR was merged into the 6.0 branch.

Discussion
----------

[Serializer] add return types

| Q             | A
| ------------- | ---
| Branch?       | 6.0
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | #40154
| License       | MIT
| Doc PR        | -

Extracted from #42496

Not all possible return types are patched for the attached components, to save breaking BC cross-components, for now at least.

Serializer's test fails. Help wanted 🙏

Commits
-------

b2090d0 [Serializer] add return types
nicolas-grekas added a commit that referenced this issue Aug 20, 2021
This PR was merged into the 6.0 branch.

Discussion
----------

[Security] add return types

| Q             | A
| ------------- | ---
| Branch?       | 6.0
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | #40154
| License       | MIT
| Doc PR        | -

Extracted from #42496

Not all possible return types are patched for the attached components, to save breaking BC cross-components, for now at least.

Commits
-------

8871327 [Security] add return types
nicolas-grekas added a commit that referenced this issue Aug 25, 2021
…o native types (nicolas-grekas)

This PR was merged into the 6.0 branch.

Discussion
----------

[CI] Ensure that all possible ``@return`` are turned into native types

| Q             | A
| ------------- | ---
| Branch?       | 6.0
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | #40154
| License       | MIT
| Doc PR        | -

This PR is the final step to close the topic of return types for Symfony 6.

It replaces #42496 by *not* adding return types to the classes/interfaces that break cross-component deps.

It enforces that all ``@return`` from 5.4 are turned into native types in 6.0, with the known list of exceptions from #42496.

Commits
-------

2b5cd7a [CI] Ensure that all possible ``@return`` are turned into native types
@nicolas-grekas
Copy link
Member Author

Task completed! We skipped adding return types were this would break BC too badly.
See #42735 for details.

symfony-splitter pushed a commit to symfony/messenger that referenced this issue Sep 28, 2021
This PR was merged into the 4.4 branch.

Discussion
----------

[PHPDoc] Fix some union type cases

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

While working on symfony/symfony#40154, I discovered some PHPDoc issues, I'm going to comment in the review. Upper branches will need some fixes too.

Commits
-------

dd1481642b [PHPDoc] Fix some union type cases
symfony-splitter pushed a commit to symfony/mailer that referenced this issue Sep 28, 2021
This PR was merged into the 4.4 branch.

Discussion
----------

[PHPDoc] Fix some union type cases

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

While working on symfony/symfony#40154, I discovered some PHPDoc issues, I'm going to comment in the review. Upper branches will need some fixes too.

Commits
-------

dd1481642b [PHPDoc] Fix some union type cases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help wanted Issues and PRs which are looking for volunteers to complete them. Keep open
Projects
None yet
Development

No branches or pull requests

5 participants