Skip to content

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

Merged
ondrejmirtes merged 2 commits intophpstan:masterfrom
jlherren:type-cast-fixes
Jul 4, 2021
Merged

Type cast fixes, add tests for intval(), boolval(), floatval()#570
ondrejmirtes merged 2 commits intophpstan:masterfrom
jlherren:type-cast-fixes

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

Development

Successfully merging this pull request may close these issues.

2 participants