mirror of
https://github.com/php/php-src.git
synced 2026-04-12 10:33:11 +02:00
Fixed bug #80047 (DatePeriod doesn't warn with custom DateTimeImmutable)
(cherry picked from commit 001e7dbb04)
This commit is contained in:
committed by
Patrick Allaert
parent
2f3d0a481a
commit
4b0bb315da
@@ -1475,6 +1475,17 @@ static int date_period_it_has_more(zend_object_iterator *iter)
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static zend_class_entry *get_base_date_class(zend_class_entry *start_ce)
|
||||
{
|
||||
zend_class_entry *tmp = start_ce;
|
||||
|
||||
while (tmp != date_ce_date && tmp != date_ce_immutable && tmp->parent) {
|
||||
tmp = tmp->parent;
|
||||
}
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/* {{{ date_period_it_current_data */
|
||||
static zval *date_period_it_current_data(zend_object_iterator *iter)
|
||||
{
|
||||
@@ -1484,7 +1495,7 @@ static zval *date_period_it_current_data(zend_object_iterator *iter)
|
||||
php_date_obj *newdateobj;
|
||||
|
||||
/* Create new object */
|
||||
php_date_instantiate(object->start_ce, &iterator->current);
|
||||
php_date_instantiate(get_base_date_class(object->start_ce), &iterator->current);
|
||||
newdateobj = Z_PHPDATE_P(&iterator->current);
|
||||
newdateobj->time = timelib_time_ctor();
|
||||
*newdateobj->time = *it_time;
|
||||
|
||||
39
ext/date/tests/bug80047.phpt
Normal file
39
ext/date/tests/bug80047.phpt
Normal file
@@ -0,0 +1,39 @@
|
||||
--TEST--
|
||||
Bug #80047: DatePeriod doesn't support custom DateTimeImmutable
|
||||
--INI--
|
||||
date.timezone=UTC
|
||||
--FILE--
|
||||
<?php
|
||||
class CustomDateTime extends DateTime {}
|
||||
class CustomDateTimeImmutable extends DateTimeImmutable {}
|
||||
|
||||
$dt = new DateTime('2022-06-24');
|
||||
$dti = new DateTimeImmutable('2022-06-24');
|
||||
$cdt = new CustomDateTime('2022-06-25');
|
||||
$cdti = new CustomDateTimeImmutable('2022-06-25');
|
||||
$i = new DateInterval('P1D');
|
||||
|
||||
$tests = [
|
||||
[ $dt, $i, $cdt ],
|
||||
[ $cdt, $i, $dt ],
|
||||
[ $cdt, $i, $cdt ],
|
||||
[ $dti, $i, $cdti ],
|
||||
[ $cdti, $i, $dti ],
|
||||
[ $cdti, $i, $cdti ],
|
||||
[ $cdt, $i, $cdti ],
|
||||
];
|
||||
|
||||
foreach ($tests as $test) {
|
||||
$dp = new DatePeriod(...$test);
|
||||
foreach ($dp as $date) {}
|
||||
echo get_class($date), "\n";
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
DateTime
|
||||
DateTime
|
||||
DateTime
|
||||
DateTimeImmutable
|
||||
DateTimeImmutable
|
||||
DateTimeImmutable
|
||||
DateTimeImmutable
|
||||
Reference in New Issue
Block a user