phpstan-src icon indicating copy to clipboard operation
phpstan-src copied to clipboard

Only use last for condition to filter scope

Open herndlm opened this issue 1 year ago • 1 comments

Improves https://github.com/phpstan/phpstan/issues/11872 but does not exactly what I hope would be possible. But with the way things currently work (going through conditions and filtering the scope) this might just not be achievable or worth it. So less precise type is better than more precise type that is wrong for me tbh :)

herndlm avatar Oct 18 '24 20:10 herndlm

This pull request has been marked as ready for review.

phpstan-bot avatar Oct 18 '24 21:10 phpstan-bot

Can you explain the PHP behaviour here like I'm five? :) I don't get what's going on.

ondrejmirtes avatar Nov 05 '24 13:11 ondrejmirtes

I think the main thing is that (see https://www.php.net/manual/en/control-structures.for.php) all cond (expr2) expressions are executed, but only the last one is used to determine if the loop should continue. Based on that it doesn't make sense (to me at least ;)) to filter the scope by any other than the last expression to narrow types.

UPDATE: having said that and while that makes sense to me, I'm not a 100% sure anymore if I adapted the right places here..

herndlm avatar Nov 05 '24 15:11 herndlm

Alright, thank you!

ondrejmirtes avatar Nov 06 '24 09:11 ondrejmirtes