File tree 3 files changed +55
-1
lines changed
3 files changed +55
-1
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,10 @@ PHP NEWS
2
2
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3
3
?? ??? 2022, PHP 8.0.23
4
4
5
+ - Date:
6
+ . Fixed bug #80047 (DatePeriod doesn't warn with custom DateTimeImmutable).
7
+ (Derick)
8
+
5
9
- DBA:
6
10
. Fixed LMDB driver memory leak on DB creation failure (Girgias)
7
11
. Fixed bug GH-9155 (dba_open("non-existing", "c-", "flatfile") segfaults).
Original file line number Diff line number Diff line change @@ -1475,6 +1475,17 @@ static int date_period_it_has_more(zend_object_iterator *iter)
1475
1475
}
1476
1476
/* }}} */
1477
1477
1478
+ static zend_class_entry * get_base_date_class (zend_class_entry * start_ce )
1479
+ {
1480
+ zend_class_entry * tmp = start_ce ;
1481
+
1482
+ while (tmp != date_ce_date && tmp != date_ce_immutable && tmp -> parent ) {
1483
+ tmp = tmp -> parent ;
1484
+ }
1485
+
1486
+ return tmp ;
1487
+ }
1488
+
1478
1489
/* {{{ date_period_it_current_data */
1479
1490
static zval * date_period_it_current_data (zend_object_iterator * iter )
1480
1491
{
@@ -1484,7 +1495,7 @@ static zval *date_period_it_current_data(zend_object_iterator *iter)
1484
1495
php_date_obj * newdateobj ;
1485
1496
1486
1497
/* Create new object */
1487
- php_date_instantiate (object -> start_ce , & iterator -> current );
1498
+ php_date_instantiate (get_base_date_class ( object -> start_ce ) , & iterator -> current );
1488
1499
newdateobj = Z_PHPDATE_P (& iterator -> current );
1489
1500
newdateobj -> time = timelib_time_ctor ();
1490
1501
* newdateobj -> time = * it_time ;
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Bug #80047: DatePeriod doesn't support custom DateTimeImmutable
3
+ --INI--
4
+ date.timezone=UTC
5
+ --FILE--
6
+ <?php
7
+ class CustomDateTime extends DateTime {}
8
+ class CustomDateTimeImmutable extends DateTimeImmutable {}
9
+
10
+ $ dt = new DateTime ('2022-06-24 ' );
11
+ $ dti = new DateTimeImmutable ('2022-06-24 ' );
12
+ $ cdt = new CustomDateTime ('2022-06-25 ' );
13
+ $ cdti = new CustomDateTimeImmutable ('2022-06-25 ' );
14
+ $ i = new DateInterval ('P1D ' );
15
+
16
+ $ tests = [
17
+ [ $ dt , $ i , $ cdt ],
18
+ [ $ cdt , $ i , $ dt ],
19
+ [ $ cdt , $ i , $ cdt ],
20
+ [ $ dti , $ i , $ cdti ],
21
+ [ $ cdti , $ i , $ dti ],
22
+ [ $ cdti , $ i , $ cdti ],
23
+ [ $ cdt , $ i , $ cdti ],
24
+ ];
25
+
26
+ foreach ($ tests as $ test ) {
27
+ $ dp = new DatePeriod (...$ test );
28
+ foreach ($ dp as $ date ) {}
29
+ echo get_class ($ date ), "\n" ;
30
+ }
31
+ ?>
32
+ --EXPECT--
33
+ DateTime
34
+ DateTime
35
+ DateTime
36
+ DateTimeImmutable
37
+ DateTimeImmutable
38
+ DateTimeImmutable
39
+ DateTimeImmutable
You can’t perform that action at this time.
0 commit comments