mirror of
https://github.com/php/php-src.git
synced 2024-09-21 18:07:23 +00:00
Merge branch 'PHP-8.0' into PHP-8.1
This commit is contained in:
commit
49a3cc63dd
4
NEWS
4
NEWS
@ -2,6 +2,10 @@ PHP NEWS
|
||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||
?? ??? ????, PHP 8.1.9
|
||||
|
||||
- Date:
|
||||
. Fixed bug #80047 (DatePeriod doesn't warn with custom DateTimeImmutable).
|
||||
(Derick)
|
||||
|
||||
- GD:
|
||||
. Fixed bug GH-8848 (imagecopyresized() error refers to the wrong argument).
|
||||
(cmb)
|
||||
|
@ -4299,6 +4299,20 @@ 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);
|
||||
|
||||
|
41
ext/date/tests/bug80042.phpt
Normal file
41
ext/date/tests/bug80042.phpt
Normal 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
|
Loading…
Reference in New Issue
Block a user