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

A union with void should error because it leads to a fatal error #9185

Closed
herndlm opened this issue Apr 13, 2023 · 6 comments
Closed

A union with void should error because it leads to a fatal error #9185

herndlm opened this issue Apr 13, 2023 · 6 comments

Comments

@herndlm
Copy link
Contributor

herndlm commented Apr 13, 2023

Bug report

https://www.php.net/manual/en/language.types.void.php states

void is a return-only type declaration indicating the function does not return a value, but the function may still terminate. Therefore, it cannot be part of a union type declaration

See https://3v4l.org/iRfF2

This was raised by @IanDelMar via szepeviktor/phpstan-wordpress#176

#6720 might be the same or is very related.

Note: Apparently WordPress uses union types of void with a scalar which annoyed me already, because I can't cast the return to a scalar without errors. E.g. https://developer.wordpress.org/reference%2Fclasses%2Fwpdb%2Fprepare%2F/

Code snippet that reproduces the problem

https://phpstan.org/r/23820230-f5a3-4533-9543-79b453cd5bd8

Expected output

There should be 2 errors IMO. The one about the invalid return type (union with void) is missing.

Did PHPStan help you today? Did it make you happy in any way?

@ondrejmirtes
Copy link
Member

Implemented: phpstan/phpstan-src#2763

@herndlm
Copy link
Contributor Author

herndlm commented Nov 22, 2023

great! but, @szepeviktor I wonder what this means for the wordpress void union types 🙈

@ondrejmirtes
Copy link
Member

@herndlm It's a fatal error in PHP so it shouldn't mean anything.

@herndlm
Copy link
Contributor Author

herndlm commented Nov 22, 2023

they use such phpdoc types (so no fatal error) heavily, but the rule doesn't cover them I guess. there's #6720 for that I suppose :)

@szepeviktor
Copy link
Contributor

It's a fatal error in PHP

Please see https://3v4l.org/jTGHE

Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants