File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed
Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -1606,6 +1606,11 @@ static zval *date_period_it_current_data(zend_object_iterator *iter)
16061606 timelib_time * it_time = object -> current ;
16071607 php_date_obj * newdateobj ;
16081608
1609+ /* Not invalidated and object is immutable, so return the same object */
1610+ if (!Z_ISUNDEF (iterator -> current )) {
1611+ return & iterator -> current ;
1612+ }
1613+
16091614 /* Create new object */
16101615 php_date_instantiate (get_base_date_class (object -> start_ce ), & iterator -> current );
16111616 newdateobj = Z_PHPDATE_P (& iterator -> current );
Original file line number Diff line number Diff line change 1+ --TEST--
2+ Multiple calls to DatePeriod iterator current() leak objects
3+ --FILE--
4+ <?php
5+ $ start = new DateTime ('2018-12-31 00:00:00 ' );
6+ $ end = new DateTime ('2019-12-31 00:00:00 ' );
7+
8+ $ interval = new DateInterval ('P1M ' );
9+ $ period = new DatePeriod ($ start , $ interval , 1 );
10+
11+ $ iter = $ period ->getIterator ();
12+ var_dump ($ iter ->current ());
13+ var_dump ($ iter ->current ());
14+ var_dump ($ iter ->current ());
15+
16+ ?>
17+ --EXPECT--
18+ object(DateTime)#9 (3) {
19+ ["date"]=>
20+ string(26) "2018-12-31 00:00:00.000000"
21+ ["timezone_type"]=>
22+ int(3)
23+ ["timezone"]=>
24+ string(3) "UTC"
25+ }
26+ object(DateTime)#9 (3) {
27+ ["date"]=>
28+ string(26) "2018-12-31 00:00:00.000000"
29+ ["timezone_type"]=>
30+ int(3)
31+ ["timezone"]=>
32+ string(3) "UTC"
33+ }
34+ object(DateTime)#9 (3) {
35+ ["date"]=>
36+ string(26) "2018-12-31 00:00:00.000000"
37+ ["timezone_type"]=>
38+ int(3)
39+ ["timezone"]=>
40+ string(3) "UTC"
41+ }
You can’t perform that action at this time.
0 commit comments