Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jdecool opened this issue Jan 30, 2023 · 4 comments · Fixed by phpstan/phpstan-src#2209

Comments

@jdecool
Copy link

jdecool commented Jan 30, 2023

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.

@VincentLanglet
Copy link
Contributor

It works fine if you cast the result of format https://phpstan.org/r/76eedf26-fcc7-4e07-9f31-2e4821e2df0b

There is something wrong with the sum computed, cf
https://phpstan.org/r/da56d0cc-d87b-425a-ab37-f48304cbacba

I'll try to fix this with phpstan/phpstan-src#2209

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src#2209

@jdecool
Copy link
Author

jdecool commented Jun 22, 2023

Thanks @ondrejmirtes & @VincentLanglet

❤️

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants