Skip to content

mt_rand assumed to always return the same value #4091

@GKFX

Description

@GKFX

Bug report

mt_rand returns a random number. The second if statement in the below is therefore not redundant. However PHPStan reports Comparison operation ">" between int<4, max> and 3 is always true..

<?php

if (mt_rand(0,10) > 3) {
    echo 'Fizz';
    if (mt_rand(0,10) > 3) {
        echo 'Buzz';
    }
}
echo "\n";

Code snippet that reproduces the problem

https://phpstan.org/r/43bf48f4-947d-4d96-9fc1-33e25fde3adb

Expected output

No output expected. Arguably, PHPStan should never assume that functions return the same value when called twice with the same arguments, but as this is a standard-library random number function it seems particularly important.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions