nette / latte

☕ Latte: the safest & truly intuitive templates for PHP. Engine for those who want the most secure PHP sites.
https://latte.nette.org
Other
1.13k stars 109 forks source link

\DatePeriod in foreach does not work with {sep} in PHP 8 #272

Closed janfejtek closed 2 years ago

janfejtek commented 3 years ago

Version: latte 2.10.3, PHP 8.0.6

Bug Description

When iterating \DatePeriod object in latte, it works fine, but when using {sep} it skips to every other DateTime object. So the result is for example 2021-01-01, 2021-01-03, ...

It is only in case of PHP 8.0, PHP 7.4 works as expected.

Steps To Reproduce

   public function renderDefault() {
        $start = \DateTime::createFromFormat("Y-m-d", "2021-01-01");
        $end = \DateTime::createFromFormat("Y-m-d", "2021-01-30");
        $this->template->period = new \DatePeriod($start, \DateInterval::createFromDateString('1 day'), $end)
   }
{foreach $period as $day}
    {$day|date:'Y-m-d'}{sep}<br/>{/sep}
{/foreach}

Results in

2021-01-01
2021-01-03
2021-01-05
...

Possible Solution

It is caused by \Latte\Runtime\CachingIterator::isLast() call, and when calling \Latte\Runtime\CachingIterator::hasNext() it is broken as well. But when using PHP's \CachingIterator::hasNext() it looks like everything is fine. But I have no idea how to fix this.

dg commented 2 years ago

https://github.com/php/php-src/issues/7979