mirror of
https://github.com/php/php-src.git
synced 2026-04-28 10:43:30 +02:00
Revert "Fixed #80047: DatePeriod doesn't warn with custom DateTimeImmutable"
This reverts commit973c3f6e24. (cherry picked from commit85f3a969dc)
This commit is contained in:
committed by
Patrick Allaert
parent
32d55f7422
commit
2f3d0a481a
@@ -4299,20 +4299,6 @@ PHP_METHOD(DatePeriod, __construct)
|
||||
}
|
||||
dpobj->start_ce = date_ce_date;
|
||||
} else {
|
||||
/* Sanity checks */
|
||||
if (start && Z_OBJCE_P(start) != date_ce_date && Z_OBJCE_P(start) != date_ce_immutable) {
|
||||
zend_string *func = get_active_function_or_method_name();
|
||||
zend_throw_error(zend_ce_exception, "%s(): Class of start date must be exactly DateTime or DateTimeImmutable, object of class %s provided", ZSTR_VAL(func), ZSTR_VAL(Z_OBJCE_P(start)->name));
|
||||
zend_string_release(func);
|
||||
RETURN_THROWS();
|
||||
}
|
||||
if (end && Z_OBJCE_P(end) != date_ce_date && Z_OBJCE_P(end) != date_ce_immutable) {
|
||||
zend_string *func = get_active_function_or_method_name();
|
||||
zend_throw_error(zend_ce_exception, "%s(): Class of end date must be exactly DateTime or DateTimeImmutable, object of class %s provided", ZSTR_VAL(func), ZSTR_VAL(Z_OBJCE_P(end)->name));
|
||||
zend_string_release(func);
|
||||
RETURN_THROWS();
|
||||
}
|
||||
|
||||
/* init */
|
||||
php_interval_obj *intobj = Z_PHPINTERVAL_P(interval);
|
||||
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
--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-24');
|
||||
$cdti = new CustomDateTimeImmutable('2022-06-24');
|
||||
$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) {
|
||||
try {
|
||||
$dp = new DatePeriod(...$test);
|
||||
} catch ( Exception $e ) {
|
||||
echo $e->getMessage(), "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
DatePeriod::__construct(): Class of end date must be exactly DateTime or DateTimeImmutable, object of class CustomDateTime provided
|
||||
DatePeriod::__construct(): Class of start date must be exactly DateTime or DateTimeImmutable, object of class CustomDateTime provided
|
||||
DatePeriod::__construct(): Class of start date must be exactly DateTime or DateTimeImmutable, object of class CustomDateTime provided
|
||||
DatePeriod::__construct(): Class of end date must be exactly DateTime or DateTimeImmutable, object of class CustomDateTimeImmutable provided
|
||||
DatePeriod::__construct(): Class of start date must be exactly DateTime or DateTimeImmutable, object of class CustomDateTimeImmutable provided
|
||||
DatePeriod::__construct(): Class of start date must be exactly DateTime or DateTimeImmutable, object of class CustomDateTimeImmutable provided
|
||||
DatePeriod::__construct(): Class of start date must be exactly DateTime or DateTimeImmutable, object of class CustomDateTime provided
|
||||
Reference in New Issue
Block a user