Merge branch 'PHP-8.0' into PHP-8.1

This commit is contained in:
Derick Rethans 2022-06-25 17:53:12 +01:00
commit 49a3cc63dd
3 changed files with 59 additions and 0 deletions

4
NEWS
View File

@ -2,6 +2,10 @@ PHP NEWS
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.1.9 ?? ??? ????, PHP 8.1.9
- Date:
. Fixed bug #80047 (DatePeriod doesn't warn with custom DateTimeImmutable).
(Derick)
- GD: - GD:
. Fixed bug GH-8848 (imagecopyresized() error refers to the wrong argument). . Fixed bug GH-8848 (imagecopyresized() error refers to the wrong argument).
(cmb) (cmb)

View File

@ -4299,6 +4299,20 @@ PHP_METHOD(DatePeriod, __construct)
} }
dpobj->start_ce = date_ce_date; dpobj->start_ce = date_ce_date;
} else { } 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 */ /* init */
php_interval_obj *intobj = Z_PHPINTERVAL_P(interval); php_interval_obj *intobj = Z_PHPINTERVAL_P(interval);

View File

@ -0,0 +1,41 @@
--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