Skip to content

PHPStan thinks static variable can be float #1870

@iluuu1994

Description

@iluuu1994

PHPStan 0.11

Summary of a problem or a feature request

I don't understand this one. Making a local static variable makes PHPStan think the variable can be a float when there's really no reason to. Removing the static removes the error.

Code snippet that reproduces the problem

function returnsInt(): int
{
	static $i = 0;
	return ++$i;
}

Function returnsInt() should return int but returns float|int.

https://phpstan.org/r/249d5f01-7caf-406d-bf12-5f6b116c3810

Expected output

No error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions