Skip to content

Commit afd4261

Browse files
committed
Merge branch 'PHP-8.2'
2 parents 1d9d1fe + dfb8cff commit afd4261

File tree

7 files changed

+35
-6
lines changed

7 files changed

+35
-6
lines changed

ext/date/php_date.c

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,36 @@ PHPAPI timelib_tzinfo *get_timezone_info(void)
582582
}
583583
return tzi;
584584
}
585+
586+
static void update_property(zend_object *object, zend_string *key, zval *prop_val)
587+
{
588+
if (ZSTR_VAL(key)[0] == '\0') { // not public
589+
const char *class_name, *prop_name;
590+
size_t prop_name_len;
591+
592+
if (zend_unmangle_property_name_ex(key, &class_name, &prop_name, &prop_name_len) == SUCCESS) {
593+
if (class_name[0] != '*') { // private
594+
zend_string *cname;
595+
zend_class_entry *ce;
596+
597+
cname = zend_string_init(class_name, strlen(class_name), 0);
598+
ce = zend_lookup_class(cname);
599+
600+
if (ce) {
601+
zend_update_property(ce, object, prop_name, prop_name_len, prop_val);
602+
}
603+
604+
zend_string_release_ex(cname, 0);
605+
} else { // protected
606+
zend_update_property(object->ce, object, prop_name, prop_name_len, prop_val);
607+
}
608+
}
609+
return;
610+
}
611+
612+
// public
613+
zend_update_property(object->ce, object, ZSTR_VAL(key), ZSTR_LEN(key), prop_val);
614+
}
585615
/* }}} */
586616

587617

@@ -2822,7 +2852,7 @@ static void restore_custom_datetime_properties(zval *object, HashTable *myht)
28222852
if (!prop_name || (Z_TYPE_P(prop_val) == IS_REFERENCE) || date_time_is_internal_property(prop_name)) {
28232853
continue;
28242854
}
2825-
add_property_zval_ex(object, ZSTR_VAL(prop_name), ZSTR_LEN(prop_name), prop_val);
2855+
update_property(Z_OBJ_P(object), prop_name, prop_val);
28262856
} ZEND_HASH_FOREACH_END();
28272857
}
28282858

@@ -3924,7 +3954,7 @@ static void restore_custom_datetimezone_properties(zval *object, HashTable *myht
39243954
if (!prop_name || (Z_TYPE_P(prop_val) == IS_REFERENCE) || date_timezone_is_internal_property(prop_name)) {
39253955
continue;
39263956
}
3927-
add_property_zval_ex(object, ZSTR_VAL(prop_name), ZSTR_LEN(prop_name), prop_val);
3957+
update_property(Z_OBJ_P(object), prop_name, prop_val);
39283958
} ZEND_HASH_FOREACH_END();
39293959
}
39303960

@@ -4551,7 +4581,7 @@ static void restore_custom_dateinterval_properties(zval *object, HashTable *myht
45514581
if (!prop_name || (Z_TYPE_P(prop_val) == IS_REFERENCE) || date_interval_is_internal_property(prop_name)) {
45524582
continue;
45534583
}
4554-
add_property_zval_ex(object, ZSTR_VAL(prop_name), ZSTR_LEN(prop_name), prop_val);
4584+
update_property(Z_OBJ_P(object), prop_name, prop_val);
45554585
} ZEND_HASH_FOREACH_END();
45564586
}
45574587

@@ -5551,7 +5581,7 @@ static void restore_custom_dateperiod_properties(zval *object, HashTable *myht)
55515581
if (!prop_name || (Z_TYPE_P(prop_val) == IS_REFERENCE) || date_period_is_internal_property(prop_name)) {
55525582
continue;
55535583
}
5554-
add_property_zval_ex(object, ZSTR_VAL(prop_name), ZSTR_LEN(prop_name), prop_val);
5584+
update_property(Z_OBJ_P(object), prop_name, prop_val);
55555585
} ZEND_HASH_FOREACH_END();
55565586
}
55575587

ext/date/tests/gh10152.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
GH-10152: Custom properties of DateTimeImmutable child classes are not serialized
2+
Bug GH-10152 (Custom properties of DateTimeImmutable child classes are not serialized)
33
--FILE--
44
<?php
55

@@ -16,7 +16,6 @@ class MyDateTimeImmutable extends DateTimeImmutable {
1616
$datetime = new MyDateTimeImmutable('2022-12-22T11:26:00Z', myProperty: true);
1717
$serialized = serialize($datetime);
1818
$unserialized = unserialize($serialized);
19-
2019
var_dump($unserialized->myProperty);
2120
?>
2221
--EXPECT--

ext/date/tests/gh10747-1.phpt

1.07 KB
Binary file not shown.

ext/date/tests/gh10747-2.phpt

1.02 KB
Binary file not shown.

ext/date/tests/gh10747-3.phpt

1.38 KB
Binary file not shown.

ext/date/tests/gh10747-4.phpt

3.12 KB
Binary file not shown.

ext/date/tests/gh10747-error.phpt

1.03 KB
Binary file not shown.

0 commit comments

Comments
 (0)