mirror of
https://github.com/php/php-src.git
synced 2024-12-05 07:46:06 +08:00
Merge branch 'PHP-8.0' into PHP-8.1
This commit is contained in:
commit
7670ee4342
@ -2459,8 +2459,10 @@ PHP_METHOD(DateTime, createFromImmutable)
|
||||
Z_PARAM_OBJECT_OF_CLASS(datetimeimmutable_object, date_ce_immutable)
|
||||
ZEND_PARSE_PARAMETERS_END();
|
||||
|
||||
php_date_instantiate(execute_data->This.value.ce ? execute_data->This.value.ce : date_ce_date, return_value);
|
||||
old_obj = Z_PHPDATE_P(datetimeimmutable_object);
|
||||
DATE_CHECK_INITIALIZED(old_obj->time, DateTimeImmutable);
|
||||
|
||||
php_date_instantiate(execute_data->This.value.ce ? execute_data->This.value.ce : date_ce_date, return_value);
|
||||
new_obj = Z_PHPDATE_P(return_value);
|
||||
|
||||
new_obj->time = timelib_time_clone(old_obj->time);
|
||||
@ -2478,8 +2480,10 @@ PHP_METHOD(DateTime, createFromInterface)
|
||||
Z_PARAM_OBJECT_OF_CLASS(datetimeinterface_object, date_ce_interface)
|
||||
ZEND_PARSE_PARAMETERS_END();
|
||||
|
||||
php_date_instantiate(execute_data->This.value.ce ? execute_data->This.value.ce : date_ce_date, return_value);
|
||||
old_obj = Z_PHPDATE_P(datetimeinterface_object);
|
||||
DATE_CHECK_INITIALIZED(old_obj->time, DateTimeInterface);
|
||||
|
||||
php_date_instantiate(execute_data->This.value.ce ? execute_data->This.value.ce : date_ce_date, return_value);
|
||||
new_obj = Z_PHPDATE_P(return_value);
|
||||
|
||||
new_obj->time = timelib_time_clone(old_obj->time);
|
||||
@ -2497,8 +2501,10 @@ PHP_METHOD(DateTimeImmutable, createFromMutable)
|
||||
Z_PARAM_OBJECT_OF_CLASS(datetime_object, date_ce_date)
|
||||
ZEND_PARSE_PARAMETERS_END();
|
||||
|
||||
php_date_instantiate(execute_data->This.value.ce ? execute_data->This.value.ce : date_ce_immutable, return_value);
|
||||
old_obj = Z_PHPDATE_P(datetime_object);
|
||||
DATE_CHECK_INITIALIZED(old_obj->time, DateTime);
|
||||
|
||||
php_date_instantiate(execute_data->This.value.ce ? execute_data->This.value.ce : date_ce_immutable, return_value);
|
||||
new_obj = Z_PHPDATE_P(return_value);
|
||||
|
||||
new_obj->time = timelib_time_clone(old_obj->time);
|
||||
@ -2516,8 +2522,10 @@ PHP_METHOD(DateTimeImmutable, createFromInterface)
|
||||
Z_PARAM_OBJECT_OF_CLASS(datetimeinterface_object, date_ce_interface)
|
||||
ZEND_PARSE_PARAMETERS_END();
|
||||
|
||||
php_date_instantiate(execute_data->This.value.ce ? execute_data->This.value.ce : date_ce_immutable, return_value);
|
||||
old_obj = Z_PHPDATE_P(datetimeinterface_object);
|
||||
DATE_CHECK_INITIALIZED(old_obj->time, DateTimeInterface);
|
||||
|
||||
php_date_instantiate(execute_data->This.value.ce ? execute_data->This.value.ce : date_ce_immutable, return_value);
|
||||
new_obj = Z_PHPDATE_P(return_value);
|
||||
|
||||
new_obj->time = timelib_time_clone(old_obj->time);
|
||||
|
50
ext/date/tests/bug-gh8471.phpt
Normal file
50
ext/date/tests/bug-gh8471.phpt
Normal file
@ -0,0 +1,50 @@
|
||||
--TEST--
|
||||
Bug GH-8471: Segmentation fault when converting immutable and mutable DateTime instances created using reflection
|
||||
--FILE--
|
||||
<?php
|
||||
$reflection = new ReflectionClass('\DateTime');
|
||||
|
||||
$mutable = $reflection->newInstanceWithoutConstructor();
|
||||
try {
|
||||
$immutable = \DateTimeImmutable::createFromMutable($mutable);
|
||||
} catch (Throwable $t) {
|
||||
echo $t->getMessage(), "\n";
|
||||
}
|
||||
|
||||
|
||||
$reflection = new ReflectionClass('\DateTime');
|
||||
|
||||
$mutable = $reflection->newInstanceWithoutConstructor();
|
||||
try {
|
||||
$immutable = \DateTimeImmutable::createFromInterface($mutable);
|
||||
} catch (Throwable $t) {
|
||||
echo $t->getMessage(), "\n";
|
||||
}
|
||||
|
||||
|
||||
$reflection = new ReflectionClass('\DateTimeImmutable');
|
||||
|
||||
$immutable = $reflection->newInstanceWithoutConstructor();
|
||||
try {
|
||||
$mutable = \DateTime::createFromImmutable($immutable);
|
||||
} catch (Throwable $t) {
|
||||
echo $t->getMessage(), "\n";
|
||||
}
|
||||
|
||||
|
||||
$reflection = new ReflectionClass('\DateTimeImmutable');
|
||||
|
||||
$immutable = $reflection->newInstanceWithoutConstructor();
|
||||
try {
|
||||
$mutable = \DateTime::createFromInterface($immutable);
|
||||
} catch (Throwable $t) {
|
||||
echo $t->getMessage(), "\n";
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
The DateTime object has not been correctly initialized by its constructor
|
||||
The DateTimeInterface object has not been correctly initialized by its constructor
|
||||
The DateTimeImmutable object has not been correctly initialized by its constructor
|
||||
The DateTimeInterface object has not been correctly initialized by its constructor
|
Loading…
Reference in New Issue
Block a user