Skip to content

Support for PHP 8.1 #86

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
Sep 14, 2021

Conversation

derrabus
Copy link
Contributor

@derrabus derrabus commented Jun 5, 2021

Q A
Documentation no
Bugfix yes
BC Break no
New Feature no
RFC no
QA no

Description

PHP 8.1 will introduce a process to add return types to internal methods, see https://wiki.php.net/rfc/internal_method_return_types

This library extends various reflection classes and overrides public methods that are affected by this change. PHP 8.1 triggers deprecation warnings unless we declare that a future version of this library will add these return types as well. We can do so by adding the ReturnTypeWillChange attribute to those methods.

This PR suggests to do just that because adding the actual return types would break code that extends our classes. A potential version 5 of this library could then add the actual return types.

There is one problematic case though: MethodReflection::getPrototype(). That method as it is currently implemented will return an array or string, depending on a parameter passed to it. The parent method ReflectionMethod::getPrototype() however will return a ReflectionMethod instance.

My recommended course of action would be to introduce two new methods getPrototypeAsString() and getPrototypeAsArray() and deprecate calling MethodReflection::getPrototype() with the PROTOTYPE_AS_ARRAY/PROTOTYPE_AS_STRING parameter.

If you agree with that, I could work on a follow-up PR.

@derrabus derrabus force-pushed the bugfix/return-type-will-change branch from 9c3fb2d to e957950 Compare June 5, 2021 09:45
@derrabus
Copy link
Contributor Author

derrabus commented Jun 5, 2021

Thanks for approving the CI run. Two static analysis jobs are failing:

  • The PHP CodeSniffer version used here apparently does not know how to handle attributes and complains about "Perl-style comments" and an unused import ReturnTypeWillChange.
  • Psalm complains about an undefined class ReturnTypeWillChange. We could either suppress that error or add symfony/polyfill-php81 to require-dev to make the class known.

Please advice how I may proceed.

@derrabus derrabus force-pushed the bugfix/return-type-will-change branch from e957950 to 399d905 Compare June 5, 2021 21:50
@Ocramius
Copy link
Member

Ocramius commented Jun 5, 2021 via email

@derrabus
Copy link
Contributor Author

derrabus commented Jun 5, 2021

symfony/polyfill-php81 contains a stub, so I've added that package.

@Ocramius
Copy link
Member

Ocramius commented Jun 5, 2021 via email

@Ocramius
Copy link
Member

Ocramius commented Jun 5, 2021 via email

@Ocramius
Copy link
Member

Marking as blocked until we test also on 8.1.x (later this year)

@Ocramius Ocramius self-assigned this Jun 17, 2021
@derrabus derrabus changed the base branch from 4.3.x to 4.4.x June 17, 2021 16:02
@derrabus derrabus force-pushed the bugfix/return-type-will-change branch 3 times, most recently from 9b6d921 to 546466d Compare June 17, 2021 16:08
@derrabus
Copy link
Contributor Author

Sure, whenever you're ready.

@derrabus
Copy link
Contributor Author

I had to bump PHP for the PHP CodeSniffer job to 8.0 because it apparently does not understand attributes when run on PHP 7.4. 😢

@derrabus derrabus force-pushed the bugfix/return-type-will-change branch 4 times, most recently from 2201517 to 74c58a7 Compare August 18, 2021 17:45
@derrabus derrabus changed the title Add ReturnTypeWillChange to extended reflection classes Support for PHP 8.1 Aug 18, 2021
Copy link
Contributor Author

@derrabus derrabus left a comment

Choose a reason for hiding this comment

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

Hello again. I've updated the PR to include a green CI for PHP 8.1. Please let me know if I can do anything else to help.

@derrabus
Copy link
Contributor Author

Hello again. This PR is one of the last blockers for Symfony's PHP 8.1 CI. Before I implement workarounds into our CI to make it pass despite the deprecation warnings triggered by laminas-code, I'd like to ask if there's anything I can do to move this PR forward.

@Ocramius
Copy link
Member

Ocramius commented Aug 29, 2021 via email

@derrabus
Copy link
Contributor Author

All right. Thanks for the heads-up.

@alexander-schranz alexander-schranz mentioned this pull request Sep 2, 2021
11 tasks
Copy link

@alexander-schranz alexander-schranz left a comment

Choose a reason for hiding this comment

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

Tested sulu with symfony 5.3 against this PR and did work. Thx for all working on this 👍

@derrabus derrabus force-pushed the bugfix/return-type-will-change branch from 74c58a7 to a7f5277 Compare September 11, 2021 14:50
@Ocramius Ocramius changed the base branch from 4.4.x to 4.5.x September 14, 2021 04:28
@Ocramius Ocramius added this to the 4.5.0 milestone Sep 14, 2021
@derrabus derrabus force-pushed the bugfix/return-type-will-change branch from a7f5277 to 2523813 Compare September 14, 2021 07:00
Signed-off-by: Alexander M. Turek <me@derrabus.de>
Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

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

🚢

Thanks @derrabus!

@Ocramius Ocramius merged commit af6921a into laminas:4.5.x Sep 14, 2021
@derrabus derrabus deleted the bugfix/return-type-will-change branch September 14, 2021 16:13
@derrabus
Copy link
Contributor Author

Thank you for the review & merge, @Ocramius!

@racile
Copy link

racile commented Nov 27, 2021

symfony/symfony#44285

@Ocramius
Copy link
Member

@racile see the related milestone: https://github.com/laminas/laminas-code/milestone/19

Likely done around end of year, I'd say, but no promises.

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

4 participants