Skip to content

Commit 9099efd

Browse files
committed
Use new serialization handler for DateTime
1 parent c13ed36 commit 9099efd

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

ext/date/php_date.c

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ static zend_object_value date_object_clone_period(zval *this_ptr TSRMLS_DC);
626626
static int date_object_compare_date(zval *d1, zval *d2 TSRMLS_DC);
627627
static HashTable *date_object_get_gc(zval *object, zval ***table, int *n TSRMLS_DC);
628628
static HashTable *date_object_get_properties(zval *object TSRMLS_DC);
629+
static HashTable *date_object_get_debug_info(zval *object, int *temp TSRMLS_DC);
629630
static HashTable *date_object_get_gc_interval(zval *object, zval ***table, int *n TSRMLS_DC);
630631
static HashTable *date_object_get_properties_interval(zval *object TSRMLS_DC);
631632
static HashTable *date_object_get_gc_period(zval *object, zval ***table, int *n TSRMLS_DC);
@@ -1993,7 +1994,8 @@ static void date_register_classes(TSRMLS_D)
19931994
memcpy(&date_object_handlers_date, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
19941995
date_object_handlers_date.clone_obj = date_object_clone_date;
19951996
date_object_handlers_date.compare_objects = date_object_compare_date;
1996-
date_object_handlers_date.get_properties = date_object_get_properties;
1997+
date_object_handlers_date.get_debug_info = date_object_get_debug_info;
1998+
date_object_handlers_date.get_serialize_info = date_object_get_properties;
19971999
date_object_handlers_date.get_gc = date_object_get_gc;
19982000
zend_class_implements(date_ce_date TSRMLS_CC, 1, date_ce_interface);
19992001

@@ -2180,6 +2182,12 @@ static HashTable *date_object_get_gc_timezone(zval *object, zval ***table, int *
21802182
return zend_std_get_properties(object TSRMLS_CC);
21812183
}
21822184

2185+
static HashTable *date_object_get_debug_info(zval *object, int *temp TSRMLS_DC)
2186+
{
2187+
*temp = 0;
2188+
return date_object_get_properties(object TSRMLS_CC);
2189+
}
2190+
21832191
static HashTable *date_object_get_properties(zval *object TSRMLS_DC)
21842192
{
21852193
HashTable *props;
@@ -2195,16 +2203,22 @@ static HashTable *date_object_get_properties(zval *object TSRMLS_DC)
21952203
return props;
21962204
}
21972205

2206+
if (!dateobj->props) {
2207+
ALLOC_HASHTABLE(dateobj->props);
2208+
ZEND_INIT_SYMTABLE_EX(dateobj->props, 3, 0);
2209+
}
2210+
zend_hash_merge(dateobj->props, props, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *), 0);
2211+
21982212
/* first we add the date and time in ISO format */
21992213
MAKE_STD_ZVAL(zv);
22002214
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);
2215+
zend_hash_update(dateobj->props, "date", sizeof("date"), &zv, sizeof(zval), NULL);
22022216

22032217
/* then we add the timezone name (or similar) */
22042218
if (dateobj->time->is_localtime) {
22052219
MAKE_STD_ZVAL(zv);
22062220
ZVAL_LONG(zv, dateobj->time->zone_type);
2207-
zend_hash_update(props, "timezone_type", 14, &zv, sizeof(zval), NULL);
2221+
zend_hash_update(dateobj->props, "timezone_type", sizeof("timezone_type"), &zv, sizeof(zval), NULL);
22082222

22092223
MAKE_STD_ZVAL(zv);
22102224
switch (dateobj->time->zone_type) {
@@ -2227,10 +2241,10 @@ static HashTable *date_object_get_properties(zval *object TSRMLS_DC)
22272241
ZVAL_STRING(zv, dateobj->time->tz_abbr, 1);
22282242
break;
22292243
}
2230-
zend_hash_update(props, "timezone", 9, &zv, sizeof(zval), NULL);
2244+
zend_hash_update(dateobj->props, "timezone", sizeof("timezone"), &zv, sizeof(zval), NULL);
22312245
}
22322246

2233-
return props;
2247+
return dateobj->props;
22342248
}
22352249

22362250
static inline zend_object_value date_object_new_timezone_ex(zend_class_entry *class_type, php_timezone_obj **ptr TSRMLS_DC)
@@ -2465,6 +2479,10 @@ static void date_object_free_storage_date(void *object TSRMLS_DC)
24652479
if (intern->time) {
24662480
timelib_time_dtor(intern->time);
24672481
}
2482+
if (intern->props) {
2483+
zend_hash_destroy(intern->props);
2484+
FREE_HASHTABLE(intern->props);
2485+
}
24682486

24692487
zend_object_std_dtor(&intern->std TSRMLS_CC);
24702488
efree(object);

0 commit comments

Comments
 (0)