1--TEST--
2Date Period iterators do not advance on valid()
3--FILE--
4<?php
5
6$start = DateTime::createFromFormat('Y-m-d', '2022-01-01');
7$end = DateTime::createFromFormat('Y-m-d', '2022-01-04');
8$interval = DateInterval::createFromDateString('1 day');
9$period = new DatePeriod($start, $interval, $end);
10$iterator = $period->getIterator();
11
12foreach ($iterator as $item) {
13    echo $item->format('Y-m-d') . "\n";
14}
15
16echo "---------STEP 2\n";
17
18foreach ($iterator as $item) {
19    $iterator->valid();
20    echo $item->format('Y-m-d') . "\n";
21}
22
23$period = new DatePeriod($start, $interval, $end, DatePeriod::EXCLUDE_START_DATE);
24$iterator = $period->getIterator();
25
26echo "---------STEP 3\n";
27
28foreach ($iterator as $item) {
29    echo $item->format('Y-m-d') . "\n";
30}
31
32echo "---------STEP 4\n";
33
34foreach ($iterator as $item) {
35    $iterator->valid();
36    echo $item->format('Y-m-d') . "\n";
37}
38?>
39--EXPECT--
402022-01-01
412022-01-02
422022-01-03
43---------STEP 2
442022-01-01
452022-01-02
462022-01-03
47---------STEP 3
482022-01-02
492022-01-03
50---------STEP 4
512022-01-02
522022-01-03
53