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

Type cast fixes, add tests for intval(), boolval(), floatval() #570

Merged
merged 2 commits into from Jul 4, 2021

Conversation

jlherren
Copy link
Contributor

@jlherren jlherren commented Jul 3, 2021

This adds return type extensions and tests for intval(), boolval(), floatval() (and doubleval()).

Additionally it includes two small fixes:

  • (int)'foo' / intval('foo') now correctly evaluate to 0 (similar for float)
  • (int)[] / intval([]) now correctly evaluate to 0 (or 1 if the array is non-empty, similar for float)

While maybe not very useful, they do not cause any notice, warning or errors in any PHP versions, thus they should be supported by PHPStan.

I left out weird constructs like strval([]) or intval(new stdClass()) which technically evaluating to 'Array' and 1 respectively. Not sure if it's useful to support that, since these always cause notices anyway (even warnings since PHP 8).

@ondrejmirtes
Copy link
Member

Awesome, thank you! I added a commit: 8bfdf17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants