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

uopz.exit=0 and never return type #172

Open
vjik opened this issue Jul 1, 2023 · 5 comments
Open

uopz.exit=0 and never return type #172

vjik opened this issue Jul 1, 2023 · 5 comments

Comments

@vjik
Copy link

vjik commented Jul 1, 2023

PHP code:

function x(): never { exit(0); };
x();

Throws error:

Fatal error: Uncaught TypeError: x(): never-returning function must not implicitly return in Command line code:1
Stack trace:
#0 Command line code(1): x()
#1 {main}
  thrown in Command line code on line 1
@vjik vjik changed the title Fatal error in PHP 8.2.7 + Xdebug 3.2.1 + uopz 7.1.1 Fatal error in PHP 8.2.7 + uopz 7.1.1 Jul 1, 2023
@blueblakk
Copy link

blueblakk commented Jul 12, 2023

I'm getting a similar error. I cannot use PHPUnit because of this.

image

Only after I remove uopz from my docker environment does it work properly.

This was tested with PHP 8.2.8 in a Docker environment on Docker Engine v24.0.2, Windows 10.

I don't seem to have this issue running Docker on MacOS Ventura.

@kornrunner
Copy link
Contributor

This is actually present since PHP 8.1 if you have configured uopz.exit=0.

I've submitted a PR which should sort it, but in case it doesn't get merged you could either set uopz.exit=1 or use my fork. Hope this helps, thanks.

kornrunner added a commit to kornrunner/uopz that referenced this issue Jul 12, 2023
kornrunner added a commit to kornrunner/uopz that referenced this issue Jul 12, 2023
kornrunner added a commit to kornrunner/uopz that referenced this issue Jul 12, 2023
kornrunner added a commit to kornrunner/uopz that referenced this issue Jul 13, 2023
kornrunner added a commit to kornrunner/uopz that referenced this issue Jul 13, 2023
@cmb69
Copy link
Collaborator

cmb69 commented Aug 2, 2024

This is a somewhat philosophical question: if exit does not stop program execution, is the never return type actually appropriate?

@kornrunner
Copy link
Contributor

uopz_allow_exit was initially implemented to allow testing code that does exit() (otherwise hitting exit terminates test execution as well).

On the other hand, never return type (which appeared later) is there to let people know that script will exit after invocation, so - from that point it's appropriate and useful.

But again, while testing - if we disable exit in order to test code that might exit- we'll end up with errors if method also has (appropriate/expected) never return type, so ... thus this issue and my PR.

Perhaps another solution would be to use uopz to modify return types of specific methods / functions. I'm willing to update the PR if there are any issues with it. Thanks!

@cmb69
Copy link
Collaborator

cmb69 commented Aug 3, 2024

I understand what this ticket is about, but I'm still not sure if we should try to "fix" the issue, for the following reasons:

My point is that I don't like to add yet another feature, that might break in the future (or might even not work under all conditions right now), especially if that feature might not be that useful. I mean, if uopz.exit=1 solves the problem, there is no issue.

Note that I'm not strictly against this change.

@remicollet, what do you think?

@cmb69 cmb69 changed the title Fatal error in PHP 8.2.7 + uopz 7.1.1 uopz.exit=0 and never return type Aug 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants