Skip to content

PHPStan incorrectly states BCMath functions can return null in PHP 8 project #5134

@khkramer

Description

@khkramer

Bug report

In a PHP 8 only codebase PHPStan currently states: Function divide() should return string but returns string|null.
It only seems to happen when strict typing is declared in the php file.

While PHP 8 bcmul and bcdiv either return a numeric string or throw an exception when dividing by zero. ( According to the Jetbrains stubs and which I have verified )

Code snippet that reproduces the problem

https://phpstan.org/r/376c482f-e055-400f-b8f5-d212d2ca1b9d

Expected output

I would have expected it to not have emitted an error in this instance.
I have also looked at the phpstan-src repository and I saw that the correct return types are present in one of the delta files, but I can't figure out why they aren't used in my instance.

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

In general I'm very happy with PHPStan providing some stability in the unsafe world that is PHP :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions