mirror of
https://github.com/php/php-src.git
synced 2025-08-15 13:38:49 +02:00
ext/date: reduce duplication in __wakeup() methods (#15791)
The only difference between `DateTime::__wakeup()` and `DateTimeImmutable::__wakeup()` is which class name is included in the error message if the initialization from the data fails. Factor out a helper method that is given the class name, and use it for both methods.
This commit is contained in:
parent
b63db81086
commit
b5c3c2d1d5
1 changed files with 12 additions and 17 deletions
|
@ -3021,8 +3021,9 @@ PHP_METHOD(DateTimeImmutable, __unserialize)
|
|||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ */
|
||||
PHP_METHOD(DateTime, __wakeup)
|
||||
/* {{{
|
||||
* Common implementation for DateTime::__wakeup() and DateTimeImmutable::__wakeup() */
|
||||
static void php_do_date_time_wakeup(INTERNAL_FUNCTION_PARAMETERS, const char *class_name)
|
||||
{
|
||||
zval *object = ZEND_THIS;
|
||||
php_date_obj *dateobj;
|
||||
|
@ -3035,29 +3036,23 @@ PHP_METHOD(DateTime, __wakeup)
|
|||
myht = Z_OBJPROP_P(object);
|
||||
|
||||
if (!php_date_initialize_from_hash(&dateobj, myht)) {
|
||||
zend_throw_error(NULL, "Invalid serialization data for DateTime object");
|
||||
zend_throw_error(NULL, "Invalid serialization data for %s object", class_name);
|
||||
RETURN_THROWS();
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ */
|
||||
PHP_METHOD(DateTime, __wakeup)
|
||||
{
|
||||
php_do_date_time_wakeup(INTERNAL_FUNCTION_PARAM_PASSTHRU, "DateTime");
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ */
|
||||
PHP_METHOD(DateTimeImmutable, __wakeup)
|
||||
{
|
||||
zval *object = ZEND_THIS;
|
||||
php_date_obj *dateobj;
|
||||
HashTable *myht;
|
||||
|
||||
ZEND_PARSE_PARAMETERS_NONE();
|
||||
|
||||
dateobj = Z_PHPDATE_P(object);
|
||||
|
||||
myht = Z_OBJPROP_P(object);
|
||||
|
||||
if (!php_date_initialize_from_hash(&dateobj, myht)) {
|
||||
zend_throw_error(NULL, "Invalid serialization data for DateTimeImmutable object");
|
||||
RETURN_THROWS();
|
||||
}
|
||||
php_do_date_time_wakeup(INTERNAL_FUNCTION_PARAM_PASSTHRU, "DateTimeImmutable");
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue