mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Fix GH-10747: Private and protected properties in serialized Date* objects throw
This commit is contained in:
parent
5eb7d7e07b
commit
31f388c353
8 changed files with 37 additions and 6 deletions
2
NEWS
2
NEWS
|
@ -29,6 +29,8 @@ PHP NEWS
|
|||
. Fix GH-10447 ('p' format specifier does not yield 'Z' for 00:00). (Derick)
|
||||
. Fix GH-10152 (Custom properties of Date's child classes are not
|
||||
serialised). (Derick)
|
||||
. Fixed bug GH-10747 (Private and protected properties in serialized Date*
|
||||
objects throw). (Derick)
|
||||
|
||||
- FFI:
|
||||
. Fixed incorrect bitshifting and masking in ffi bitfield. (nielsdos)
|
||||
|
|
|
@ -565,6 +565,36 @@ PHPAPI timelib_tzinfo *get_timezone_info(void)
|
|||
}
|
||||
return tzi;
|
||||
}
|
||||
|
||||
static void update_property(zend_object *object, zend_string *key, zval *prop_val)
|
||||
{
|
||||
if (ZSTR_VAL(key)[0] == '\0') { // not public
|
||||
const char *class_name, *prop_name;
|
||||
size_t prop_name_len;
|
||||
|
||||
if (zend_unmangle_property_name_ex(key, &class_name, &prop_name, &prop_name_len) == SUCCESS) {
|
||||
if (class_name[0] != '*') { // private
|
||||
zend_string *cname;
|
||||
zend_class_entry *ce;
|
||||
|
||||
cname = zend_string_init(class_name, strlen(class_name), 0);
|
||||
ce = zend_lookup_class(cname);
|
||||
|
||||
if (ce) {
|
||||
zend_update_property(ce, object, prop_name, prop_name_len, prop_val);
|
||||
}
|
||||
|
||||
zend_string_release_ex(cname, 0);
|
||||
} else { // protected
|
||||
zend_update_property(object->ce, object, prop_name, prop_name_len, prop_val);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// public
|
||||
zend_update_property(object->ce, object, ZSTR_VAL(key), ZSTR_LEN(key), prop_val);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
|
@ -2794,7 +2824,7 @@ static void restore_custom_datetime_properties(zval *object, HashTable *myht)
|
|||
if (!prop_name || (Z_TYPE_P(prop_val) == IS_REFERENCE) || date_time_is_internal_property(prop_name)) {
|
||||
continue;
|
||||
}
|
||||
add_property_zval_ex(object, ZSTR_VAL(prop_name), ZSTR_LEN(prop_name), prop_val);
|
||||
update_property(Z_OBJ_P(object), prop_name, prop_val);
|
||||
} ZEND_HASH_FOREACH_END();
|
||||
}
|
||||
|
||||
|
@ -3828,7 +3858,7 @@ static void restore_custom_datetimezone_properties(zval *object, HashTable *myht
|
|||
if (!prop_name || (Z_TYPE_P(prop_val) == IS_REFERENCE) || date_timezone_is_internal_property(prop_name)) {
|
||||
continue;
|
||||
}
|
||||
add_property_zval_ex(object, ZSTR_VAL(prop_name), ZSTR_LEN(prop_name), prop_val);
|
||||
update_property(Z_OBJ_P(object), prop_name, prop_val);
|
||||
} ZEND_HASH_FOREACH_END();
|
||||
}
|
||||
|
||||
|
@ -4456,7 +4486,7 @@ static void restore_custom_dateinterval_properties(zval *object, HashTable *myht
|
|||
if (!prop_name || (Z_TYPE_P(prop_val) == IS_REFERENCE) || date_interval_is_internal_property(prop_name)) {
|
||||
continue;
|
||||
}
|
||||
add_property_zval_ex(object, ZSTR_VAL(prop_name), ZSTR_LEN(prop_name), prop_val);
|
||||
update_property(Z_OBJ_P(object), prop_name, prop_val);
|
||||
} ZEND_HASH_FOREACH_END();
|
||||
}
|
||||
|
||||
|
@ -5418,7 +5448,7 @@ static void restore_custom_dateperiod_properties(zval *object, HashTable *myht)
|
|||
if (!prop_name || (Z_TYPE_P(prop_val) == IS_REFERENCE) || date_period_is_internal_property(prop_name)) {
|
||||
continue;
|
||||
}
|
||||
add_property_zval_ex(object, ZSTR_VAL(prop_name), ZSTR_LEN(prop_name), prop_val);
|
||||
update_property(Z_OBJ_P(object), prop_name, prop_val);
|
||||
} ZEND_HASH_FOREACH_END();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
--TEST--
|
||||
GH-10152: Custom properties of DateTimeImmutable child classes are not serialized
|
||||
Bug GH-10152 (Custom properties of DateTimeImmutable child classes are not serialized)
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
|
@ -16,7 +16,6 @@ class MyDateTimeImmutable extends DateTimeImmutable {
|
|||
$datetime = new MyDateTimeImmutable('2022-12-22T11:26:00Z', myProperty: true);
|
||||
$serialized = serialize($datetime);
|
||||
$unserialized = unserialize($serialized);
|
||||
|
||||
var_dump($unserialized->myProperty);
|
||||
?>
|
||||
--EXPECT--
|
||||
|
|
BIN
ext/date/tests/gh10747-1.phpt
Normal file
BIN
ext/date/tests/gh10747-1.phpt
Normal file
Binary file not shown.
BIN
ext/date/tests/gh10747-2.phpt
Normal file
BIN
ext/date/tests/gh10747-2.phpt
Normal file
Binary file not shown.
BIN
ext/date/tests/gh10747-3.phpt
Normal file
BIN
ext/date/tests/gh10747-3.phpt
Normal file
Binary file not shown.
BIN
ext/date/tests/gh10747-4.phpt
Normal file
BIN
ext/date/tests/gh10747-4.phpt
Normal file
Binary file not shown.
BIN
ext/date/tests/gh10747-error.phpt
Normal file
BIN
ext/date/tests/gh10747-error.phpt
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue