Skip to content

Handle PHP 8.1 "never" return type#141

Merged
antecedent merged 3 commits into
masterfrom
add/handle-never-return-type
Sep 18, 2023
Merged

Handle PHP 8.1 "never" return type#141
antecedent merged 3 commits into
masterfrom
add/handle-never-return-type

Conversation

@anomiex

@anomiex anomiex commented Aug 16, 2023

Copy link
Copy Markdown
Collaborator

PHP 8.1 added a "never" return type that indicates that the function will never return, and raises a fatal error if such a function includes a return. We need to detect and handle such functions in a similar manner as we handle "void".

Also it turns out that the error handling for a "void" redefinition trying to return a value was broken, giving an error like

Fatal error: Uncaught Error: Undefined constant "thrownew\Patchwork\Exceptions\NonNullToVoid" in file line #

so I added a test for that too and adjusted the condense function to collapse whitespace to a single space instead of stripping it completely.

Fixes #140

PHP 8.1 added a "never" return type that indicates that the function
will never return, and raises a fatal error if such a function includes
a `return`. We need to detect and handle such functions in a similar
manner as we handle "void".

Also it turns out that the error handling for a "void" redefinition
trying to return a value was broken, giving an error like
```
Fatal error: Uncaught Error: Undefined constant "thrownew\Patchwork\Exceptions\NonNullToVoid" in file line #
```
so I added a test for that too and adjusted the condense function to
collapse whitespace to a single space instead of stripping it
completely.
@anomiex anomiex requested review from antecedent and jrfnl August 16, 2023 15:31
@anomiex anomiex self-assigned this Aug 16, 2023
@d-claassen

Copy link
Copy Markdown

Hey! After running into the same issue, Google led me to this issue / PR. I can confirm this PR solved the described issue on the repo I've been working on! 👍

@antecedent antecedent merged commit f2dae08 into master Sep 18, 2023
@antecedent

Copy link
Copy Markdown
Owner

This is now live in 2.1.26. My apologies for the delay, and thanks to @anomiex for contributing!

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.

Handle PHP 8.1 and PHPUnit 10, 'never' return type

3 participants