Skip to content

Instruction seems to be not complety interpreted when using DateTime::format('N') #8803

@jdecool

Description

@jdecool

Bug report

I've a code which iterate on dates and perform some operations using DateTime::format('N') to loop over an array indexed by day in numeric format.

The code looks like something like this:

$from = new DateTimeImmutable('2023-01-30');
for ($offset = 1; $offset <= 14; $offset++) {
    $value = $from->format('N') + $offset;
	var_dump($value);
    if ($value > 7) {
    }
}

The previous code output number from 2 to 15, but phpstan considering that the condition is always false which is wrong.

Comparison operation ">" between 1|2|3|4|5|6|7 and 7 is always false.

Code snippet that reproduces the problem

Expected output

No error should be output.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions