Skip to content

Commit 84f913d

Browse files
committed
Modify a copy of DateTime props when returned from get_properties handler
1 parent 678ef6a commit 84f913d

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

ext/date/php_date.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2195,16 +2195,22 @@ static HashTable *date_object_get_properties(zval *object TSRMLS_DC)
21952195
return props;
21962196
}
21972197

2198+
if (!dateobj->props) {
2199+
ALLOC_HASHTABLE(dateobj->props);
2200+
ZEND_INIT_SYMTABLE_EX(dateobj->props, 3, 0);
2201+
}
2202+
zend_hash_merge(dateobj->props, props, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *), 0);
2203+
21982204
/* first we add the date and time in ISO format */
21992205
MAKE_STD_ZVAL(zv);
22002206
ZVAL_STRING(zv, date_format("Y-m-d H:i:s", 12, dateobj->time, 1), 0);
2201-
zend_hash_update(props, "date", 5, &zv, sizeof(zval), NULL);
2207+
zend_hash_update(dateobj->props, "date", sizeof("date"), &zv, sizeof(zval), NULL);
22022208

22032209
/* then we add the timezone name (or similar) */
22042210
if (dateobj->time->is_localtime) {
22052211
MAKE_STD_ZVAL(zv);
22062212
ZVAL_LONG(zv, dateobj->time->zone_type);
2207-
zend_hash_update(props, "timezone_type", 14, &zv, sizeof(zval), NULL);
2213+
zend_hash_update(dateobj->props, "timezone_type", sizeof("timezone_type"), &zv, sizeof(zval), NULL);
22082214

22092215
MAKE_STD_ZVAL(zv);
22102216
switch (dateobj->time->zone_type) {
@@ -2227,10 +2233,10 @@ static HashTable *date_object_get_properties(zval *object TSRMLS_DC)
22272233
ZVAL_STRING(zv, dateobj->time->tz_abbr, 1);
22282234
break;
22292235
}
2230-
zend_hash_update(props, "timezone", 9, &zv, sizeof(zval), NULL);
2236+
zend_hash_update(dateobj->props, "timezone", sizeof("timezone"), &zv, sizeof(zval), NULL);
22312237
}
22322238

2233-
return props;
2239+
return dateobj->props;
22342240
}
22352241

22362242
static inline zend_object_value date_object_new_timezone_ex(zend_class_entry *class_type, php_timezone_obj **ptr TSRMLS_DC)
@@ -2465,6 +2471,10 @@ static void date_object_free_storage_date(void *object TSRMLS_DC)
24652471
if (intern->time) {
24662472
timelib_time_dtor(intern->time);
24672473
}
2474+
if (intern->props) {
2475+
zend_hash_destroy(intern->props);
2476+
FREE_HASHTABLE(intern->props);
2477+
}
24682478

24692479
zend_object_std_dtor(&intern->std TSRMLS_CC);
24702480
efree(object);

0 commit comments

Comments
 (0)