Skip to content

Casting an int (or a decimal-int-string) as float yields a finite-float #15767

Open
phpstan/phpstan-src
#7102

Description

@claudepache

Bug report

If $x is int, PHPStan fails to acknowledge that (float) $x cannot be non-finite.

Code snippet that reproduces the problem

https://phpstan.org/r/2fa00c9c-2f4d-4953-be97-55e2327f4c0a

Expected output

No error.

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

No response

Activity

  1. claudepache commented on Nov 17, 2026

    @claudepache
    Author

    Of course, alternative ways to cast to float should also be considered:

    • settype($a, 'float')
    • $a + 0.0
    • ...
  2. added this to the Easy fixes milestone on Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions