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

Incorrect getopt return type? #4987

Closed
mind-bending-forks opened this issue May 11, 2021 · 2 comments
Closed

Incorrect getopt return type? #4987

mind-bending-forks opened this issue May 11, 2021 · 2 comments

Comments

@mind-bending-forks
Copy link

Please excuse me not sending a pull request for this. Please let me know if you need me to.

phpstan seems to think that between PHP 7.1 and 7.4, getopt returned array<string, array<int, mixed>|string|false>. For those versions of PHP, phpstan returns the following error if you attempt to do a strict comparison of the output of getopt with false.

Strict comparison using === between array<string, array<int, mixed>|string|false> and false will always evaluate to false.

I have taken a look at old versions of the documentation for getopt using the Wayback Machine, and while the documented method signature says that previously returned array only, the "Return Values" section always appears to have reported that it will return false on failure.

Therefore, I think that the error message being reported for PHP versions 7.1 to 7.4 is potentially incorrect - and in an unsafe way, since if someone stops checking for false due to this error message it could result in error conditions being missed.

I suggest that phpstan should be updated to define the return type for getopt as array<string, array<int, mixed>|string|false>|false for those PHP versions. (So, add false as a permitted return type).

@ondrejmirtes
Copy link
Member

Fixed, thanks: phpstan/phpstan-src@94b6c03

@github-actions
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 Jun 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants