twigphp / Twig

Twig, the flexible, fast, and secure template language for PHP
https://twig.symfony.com/
BSD 3-Clause "New" or "Revised" License
8.18k stars 1.25k forks source link

Fix isset in ForLoopNode #4280

Closed ruudk closed 2 months ago

ruudk commented 2 months ago

Even though the code works perfectly fine, PHPStan doesn't understand it.

Offset 'revindex0' does not exist on array{parent: array{index0: int<1, max>, index: int<2, max>, first: false, revindex0?: int, revindex?: int, length: int<0, max>, last?: bool}. Offset 'revindex' does not exist on array{parent: array{index0: int<1, max>, index: int<2, max>, first: false, revindex0: int, revindex?: int, length: int<0, max>, last?: bool}.

Since we want to work with revindex and revindex0, we can better check for their existence, instead of length.

/cc @stof @fabpot

fabpot commented 2 months ago

Thank you @ruudk.