Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FP: Comparison operation ">=" between 0 and 1 is always false. #2673

@dktapps

Description

@dktapps

Bug report

This doesn't occur on 0.11.19, it seems new to 0.12.0.

The bug is hard to explain, I'll let the code do the talking.

Code snippet that reproduces the problem

<?php

declare(strict_types=1);

class MyClass{
	public $t = 0;

	public function test() : void{
		$this->t = 0;
		$this->bump();
		if($this->t >= 1){
			echo "hi";
		}
	}

	private function bump() : int{
		++$this->t;
		return 0;
	}
}

Broken:
https://phpstan.org/r/e44e4d31-98eb-44c0-8bcb-5452b6c67bf2

Strange that if bump() returns void, no error is reported, ex: https://phpstan.org/r/975a9409-6b28-438e-b5dd-81d4d9a1684d

Expected output

No error should be reported.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions