From 4f56807d8a20fc1f70b1a6cf49eb425e28ac7c20 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Fri, 29 Apr 2022 16:31:26 +0100 Subject: [PATCH] Add DatePeriod's __serialize and __unserialize methods --- ext/date/php_date.c | 66 +++++- ext/date/php_date.stub.php | 4 + ext/date/php_date_arginfo.h | 10 +- ext/date/tests/DatePeriod_serialize-001.phpt | 160 +++++++++++++ ext/date/tests/DatePeriod_serialize-002.phpt | 210 ++++++++++++++++++ ext/date/tests/DatePeriod_serialize-003.phpt | 209 +++++++++++++++++ ext/date/tests/DatePeriod_serialize-004.phpt | 207 +++++++++++++++++ .../{bug53437.phpt => bug53437_var0.phpt} | 2 +- ext/date/tests/bug53437_var1.phpt | 2 +- 9 files changed, 857 insertions(+), 13 deletions(-) create mode 100644 ext/date/tests/DatePeriod_serialize-001.phpt create mode 100644 ext/date/tests/DatePeriod_serialize-002.phpt create mode 100644 ext/date/tests/DatePeriod_serialize-003.phpt create mode 100644 ext/date/tests/DatePeriod_serialize-004.phpt rename ext/date/tests/{bug53437.phpt => bug53437_var0.phpt} (99%) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index ed66a4a4b9a70..40ab52213f6df 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -5015,17 +5015,9 @@ static HashTable *date_object_get_gc_period(zend_object *object, zval **table, i return zend_std_get_properties(object); } /* }}} */ -static HashTable *date_object_get_properties_period(zend_object *object) /* {{{ */ +static void date_period_object_to_hash(php_period_obj *period_obj, HashTable *props) { - HashTable *props; - zval zv; - php_period_obj *period_obj; - - period_obj = php_period_obj_from_obj(object); - props = zend_std_get_properties(object); - if (!period_obj->start) { - return props; - } + zval zv; if (period_obj->start) { php_date_obj *date_obj; @@ -5074,6 +5066,20 @@ static HashTable *date_object_get_properties_period(zend_object *object) /* {{{ ZVAL_BOOL(&zv, period_obj->include_start_date); zend_hash_str_update(props, "include_start_date", sizeof("include_start_date")-1, &zv); +} + +static HashTable *date_object_get_properties_period(zend_object *object) /* {{{ */ +{ + HashTable *props; + php_period_obj *period_obj; + + period_obj = php_period_obj_from_obj(object); + props = zend_std_get_properties(object); + if (!period_obj->start) { + return props; + } + + date_period_object_to_hash(period_obj, props); return props; } /* }}} */ @@ -5179,6 +5185,46 @@ PHP_METHOD(DatePeriod, __set_state) } /* }}} */ +/* {{{ */ +PHP_METHOD(DatePeriod, __serialize) +{ + zval *object = ZEND_THIS; + php_period_obj *period_obj; + HashTable *myht; + + ZEND_PARSE_PARAMETERS_NONE(); + + period_obj = Z_PHPPERIOD_P(object); + DATE_CHECK_INITIALIZED(period_obj->start, DatePeriod); + + array_init(return_value); + myht = Z_ARRVAL_P(return_value); + date_period_object_to_hash(period_obj, myht); +} +/* }}} */ + + +/* {{{ */ +PHP_METHOD(DatePeriod, __unserialize) +{ + zval *object = ZEND_THIS; + php_period_obj *period_obj; + zval *array; + HashTable *myht; + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(array) + ZEND_PARSE_PARAMETERS_END(); + + period_obj = Z_PHPPERIOD_P(object); + myht = Z_ARRVAL_P(array); + + if (!php_date_period_initialize_from_hash(period_obj, myht)) { + zend_throw_error(NULL, "Invalid serialization data for DatePeriod object"); + } +} +/* }}} */ + /* {{{ */ PHP_METHOD(DatePeriod, __wakeup) { diff --git a/ext/date/php_date.stub.php b/ext/date/php_date.stub.php index 5cb435647c946..ae59c144614f3 100644 --- a/ext/date/php_date.stub.php +++ b/ext/date/php_date.stub.php @@ -513,6 +513,10 @@ public function getDateInterval(): DateInterval {} /** @tentative-return-type */ public function getRecurrences(): ?int {} + public function __serialize(): array; + + public function __unserialize(array $data): void; + /** @tentative-return-type */ public function __wakeup(): void {} diff --git a/ext/date/php_date_arginfo.h b/ext/date/php_date_arginfo.h index 722f38b1793d6..5c735b7cba43e 100644 --- a/ext/date/php_date_arginfo.h +++ b/ext/date/php_date_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 4845891ab3872f292438de639953e2022f849125 */ + * Stub hash: db6fd5b6c366dd8ee48ead99d235baa86e564401 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_strtotime, 0, 1, MAY_BE_LONG|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, datetime, IS_STRING, 0) @@ -480,6 +480,10 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_DatePeriod_getRecurrences, 0, 0, IS_LONG, 1) ZEND_END_ARG_INFO() +#define arginfo_class_DatePeriod___serialize arginfo_timezone_abbreviations_list + +#define arginfo_class_DatePeriod___unserialize arginfo_class_DateTimeInterface___unserialize + #define arginfo_class_DatePeriod___wakeup arginfo_class_DateTimeInterface___wakeup ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(arginfo_class_DatePeriod___set_state, 0, 1, DatePeriod, 0) @@ -575,6 +579,8 @@ ZEND_METHOD(DatePeriod, getStartDate); ZEND_METHOD(DatePeriod, getEndDate); ZEND_METHOD(DatePeriod, getDateInterval); ZEND_METHOD(DatePeriod, getRecurrences); +ZEND_METHOD(DatePeriod, __serialize); +ZEND_METHOD(DatePeriod, __unserialize); ZEND_METHOD(DatePeriod, __wakeup); ZEND_METHOD(DatePeriod, __set_state); ZEND_METHOD(DatePeriod, getIterator); @@ -734,6 +740,8 @@ static const zend_function_entry class_DatePeriod_methods[] = { ZEND_ME(DatePeriod, getEndDate, arginfo_class_DatePeriod_getEndDate, ZEND_ACC_PUBLIC) ZEND_ME(DatePeriod, getDateInterval, arginfo_class_DatePeriod_getDateInterval, ZEND_ACC_PUBLIC) ZEND_ME(DatePeriod, getRecurrences, arginfo_class_DatePeriod_getRecurrences, ZEND_ACC_PUBLIC) + ZEND_ME(DatePeriod, __serialize, arginfo_class_DatePeriod___serialize, ZEND_ACC_PUBLIC) + ZEND_ME(DatePeriod, __unserialize, arginfo_class_DatePeriod___unserialize, ZEND_ACC_PUBLIC) ZEND_ME(DatePeriod, __wakeup, arginfo_class_DatePeriod___wakeup, ZEND_ACC_PUBLIC) ZEND_ME(DatePeriod, __set_state, arginfo_class_DatePeriod___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) ZEND_ME(DatePeriod, getIterator, arginfo_class_DatePeriod_getIterator, ZEND_ACC_PUBLIC) diff --git a/ext/date/tests/DatePeriod_serialize-001.phpt b/ext/date/tests/DatePeriod_serialize-001.phpt new file mode 100644 index 0000000000000..0f555ab425145 --- /dev/null +++ b/ext/date/tests/DatePeriod_serialize-001.phpt @@ -0,0 +1,160 @@ +--TEST-- +Test DatePeriod::__serialize and DatePeriod::__unserialize (ISO String) +--FILE-- +__serialize()); + +?> +--EXPECTF-- +Original object: +object(DatePeriod)#1 (6) { + ["start"]=> + object(DateTime)#2 (3) { + ["date"]=> + string(26) "2012-07-01 00:00:00.000000" + ["timezone_type"]=> + int(1) + ["timezone"]=> + string(6) "+00:00" + } + ["current"]=> + NULL + ["end"]=> + NULL + ["interval"]=> + object(DateInterval)#3 (10) { + ["y"]=> + int(0) + ["m"]=> + int(0) + ["d"]=> + int(7) + ["h"]=> + int(0) + ["i"]=> + int(0) + ["s"]=> + int(0) + ["f"]=> + float(0) + ["invert"]=> + int(0) + ["days"]=> + bool(false) + ["from_string"]=> + bool(false) + } + ["recurrences"]=> + int(5) + ["include_start_date"]=> + bool(true) +} + + +Serialised object: +string(411) "O:10:"DatePeriod":6:{s:5:"start";O:8:"DateTime":3:{s:4:"date";s:26:"2012-07-01 00:00:00.000000";s:13:"timezone_type";i:1;s:8:"timezone";s:6:"+00:00";}s:7:"current";N;s:3:"end";N;s:8:"interval";O:12:"DateInterval":10:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:7;s:1:"h";i:0;s:1:"i";i:0;s:1:"s";i:0;s:1:"f";d:0;s:6:"invert";i:0;s:4:"days";b:0;s:11:"from_string";b:0;}s:11:"recurrences";i:5;s:18:"include_start_date";b:1;}" + + +Unserialised object: +object(DatePeriod)#5 (6) { + ["start"]=> + object(DateTime)#6 (3) { + ["date"]=> + string(26) "2012-07-01 00:00:00.000000" + ["timezone_type"]=> + int(1) + ["timezone"]=> + string(6) "+00:00" + } + ["current"]=> + NULL + ["end"]=> + NULL + ["interval"]=> + object(DateInterval)#4 (10) { + ["y"]=> + int(0) + ["m"]=> + int(0) + ["d"]=> + int(7) + ["h"]=> + int(0) + ["i"]=> + int(0) + ["s"]=> + int(0) + ["f"]=> + float(0) + ["invert"]=> + int(0) + ["days"]=> + bool(false) + ["from_string"]=> + bool(false) + } + ["recurrences"]=> + int(5) + ["include_start_date"]=> + bool(true) +} + + +Calling __serialize manually: +array(6) { + ["start"]=> + object(DateTime)#7 (3) { + ["date"]=> + string(26) "2012-07-01 00:00:00.000000" + ["timezone_type"]=> + int(1) + ["timezone"]=> + string(6) "+00:00" + } + ["current"]=> + NULL + ["end"]=> + NULL + ["interval"]=> + object(DateInterval)#8 (10) { + ["y"]=> + int(0) + ["m"]=> + int(0) + ["d"]=> + int(7) + ["h"]=> + int(0) + ["i"]=> + int(0) + ["s"]=> + int(0) + ["f"]=> + float(0) + ["invert"]=> + int(0) + ["days"]=> + bool(false) + ["from_string"]=> + bool(false) + } + ["recurrences"]=> + int(5) + ["include_start_date"]=> + bool(true) +} diff --git a/ext/date/tests/DatePeriod_serialize-002.phpt b/ext/date/tests/DatePeriod_serialize-002.phpt new file mode 100644 index 0000000000000..7e9d3e62dae54 --- /dev/null +++ b/ext/date/tests/DatePeriod_serialize-002.phpt @@ -0,0 +1,210 @@ +--TEST-- +Test DatePeriod::__serialize and DatePeriod::__unserialize (start/end) +--FILE-- +__serialize()); + +echo "\n\nIterate of unserialised object:\n"; +foreach ( $e as $d ) +{ + echo $d->format(DateTime::ISO8601), "\n"; +} +?> +--EXPECTF-- +Original object: +object(DatePeriod)#4 (6) { + ["start"]=> + object(DateTimeImmutable)#5 (3) { + ["date"]=> + string(26) "1978-12-22 09:15:00.000000" + ["timezone_type"]=> + int(3) + ["timezone"]=> + string(16) "Europe/Amsterdam" + } + ["current"]=> + NULL + ["end"]=> + object(DateTimeImmutable)#6 (3) { + ["date"]=> + string(26) "2022-04-29 15:51:56.000000" + ["timezone_type"]=> + int(3) + ["timezone"]=> + string(13) "Europe/London" + } + ["interval"]=> + object(DateInterval)#7 (10) { + ["y"]=> + int(2) + ["m"]=> + int(6) + ["d"]=> + int(0) + ["h"]=> + int(0) + ["i"]=> + int(0) + ["s"]=> + int(0) + ["f"]=> + float(0) + ["invert"]=> + int(0) + ["days"]=> + bool(false) + ["from_string"]=> + bool(false) + } + ["recurrences"]=> + int(1) + ["include_start_date"]=> + bool(true) +} + + +Serialised object: +string(565) "O:10:"DatePeriod":6:{s:5:"start";O:17:"DateTimeImmutable":3:{s:4:"date";s:26:"1978-12-22 09:15:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:16:"Europe/Amsterdam";}s:7:"current";N;s:3:"end";O:17:"DateTimeImmutable":3:{s:4:"date";s:26:"2022-04-29 15:51:56.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:13:"Europe/London";}s:8:"interval";O:12:"DateInterval":10:{s:1:"y";i:2;s:1:"m";i:6;s:1:"d";i:0;s:1:"h";i:0;s:1:"i";i:0;s:1:"s";i:0;s:1:"f";d:0;s:6:"invert";i:0;s:4:"days";b:0;s:11:"from_string";b:0;}s:11:"recurrences";i:1;s:18:"include_start_date";b:1;}" + + +Unserialised object: +object(DatePeriod)#1 (6) { + ["start"]=> + object(DateTimeImmutable)#2 (3) { + ["date"]=> + string(26) "1978-12-22 09:15:00.000000" + ["timezone_type"]=> + int(3) + ["timezone"]=> + string(16) "Europe/Amsterdam" + } + ["current"]=> + NULL + ["end"]=> + object(DateTimeImmutable)#8 (3) { + ["date"]=> + string(26) "2022-04-29 15:51:56.000000" + ["timezone_type"]=> + int(3) + ["timezone"]=> + string(13) "Europe/London" + } + ["interval"]=> + object(DateInterval)#9 (10) { + ["y"]=> + int(2) + ["m"]=> + int(6) + ["d"]=> + int(0) + ["h"]=> + int(0) + ["i"]=> + int(0) + ["s"]=> + int(0) + ["f"]=> + float(0) + ["invert"]=> + int(0) + ["days"]=> + bool(false) + ["from_string"]=> + bool(false) + } + ["recurrences"]=> + int(1) + ["include_start_date"]=> + bool(true) +} + + +Calling __serialize manually: +array(6) { + ["start"]=> + object(DateTimeImmutable)#10 (3) { + ["date"]=> + string(26) "1978-12-22 09:15:00.000000" + ["timezone_type"]=> + int(3) + ["timezone"]=> + string(16) "Europe/Amsterdam" + } + ["current"]=> + NULL + ["end"]=> + object(DateTimeImmutable)#11 (3) { + ["date"]=> + string(26) "2022-04-29 15:51:56.000000" + ["timezone_type"]=> + int(3) + ["timezone"]=> + string(13) "Europe/London" + } + ["interval"]=> + object(DateInterval)#12 (10) { + ["y"]=> + int(2) + ["m"]=> + int(6) + ["d"]=> + int(0) + ["h"]=> + int(0) + ["i"]=> + int(0) + ["s"]=> + int(0) + ["f"]=> + float(0) + ["invert"]=> + int(0) + ["days"]=> + bool(false) + ["from_string"]=> + bool(false) + } + ["recurrences"]=> + int(1) + ["include_start_date"]=> + bool(true) +} + + +Iterate of unserialised object: +1978-12-22T09:15:00+0100 +1981-06-22T09:15:00+0200 +1983-12-22T09:15:00+0100 +1986-06-22T09:15:00+0200 +1988-12-22T09:15:00+0100 +1991-06-22T09:15:00+0200 +1993-12-22T09:15:00+0100 +1996-06-22T09:15:00+0200 +1998-12-22T09:15:00+0100 +2001-06-22T09:15:00+0200 +2003-12-22T09:15:00+0100 +2006-06-22T09:15:00+0200 +2008-12-22T09:15:00+0100 +2011-06-22T09:15:00+0200 +2013-12-22T09:15:00+0100 +2016-06-22T09:15:00+0200 +2018-12-22T09:15:00+0100 +2021-06-22T09:15:00+0200 diff --git a/ext/date/tests/DatePeriod_serialize-003.phpt b/ext/date/tests/DatePeriod_serialize-003.phpt new file mode 100644 index 0000000000000..ada8c7478f586 --- /dev/null +++ b/ext/date/tests/DatePeriod_serialize-003.phpt @@ -0,0 +1,209 @@ +--TEST-- +Test DatePeriod::__serialize and DatePeriod::__unserialize (start/end) +--FILE-- +__serialize()); + +echo "\n\nIterate of unserialised object:\n"; +foreach ( $e as $d ) +{ + echo $d->format(DateTime::ISO8601), "\n"; +} +?> +--EXPECTF-- +Original object: +object(DatePeriod)#4 (6) { + ["start"]=> + object(DateTimeImmutable)#5 (3) { + ["date"]=> + string(26) "1978-12-22 09:15:00.000000" + ["timezone_type"]=> + int(3) + ["timezone"]=> + string(16) "Europe/Amsterdam" + } + ["current"]=> + NULL + ["end"]=> + object(DateTimeImmutable)#6 (3) { + ["date"]=> + string(26) "2022-04-29 15:51:56.000000" + ["timezone_type"]=> + int(3) + ["timezone"]=> + string(13) "Europe/London" + } + ["interval"]=> + object(DateInterval)#7 (10) { + ["y"]=> + int(2) + ["m"]=> + int(6) + ["d"]=> + int(0) + ["h"]=> + int(0) + ["i"]=> + int(0) + ["s"]=> + int(0) + ["f"]=> + float(0) + ["invert"]=> + int(0) + ["days"]=> + bool(false) + ["from_string"]=> + bool(false) + } + ["recurrences"]=> + int(0) + ["include_start_date"]=> + bool(false) +} + + +Serialised object: +string(565) "O:10:"DatePeriod":6:{s:5:"start";O:17:"DateTimeImmutable":3:{s:4:"date";s:26:"1978-12-22 09:15:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:16:"Europe/Amsterdam";}s:7:"current";N;s:3:"end";O:17:"DateTimeImmutable":3:{s:4:"date";s:26:"2022-04-29 15:51:56.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:13:"Europe/London";}s:8:"interval";O:12:"DateInterval":10:{s:1:"y";i:2;s:1:"m";i:6;s:1:"d";i:0;s:1:"h";i:0;s:1:"i";i:0;s:1:"s";i:0;s:1:"f";d:0;s:6:"invert";i:0;s:4:"days";b:0;s:11:"from_string";b:0;}s:11:"recurrences";i:0;s:18:"include_start_date";b:0;}" + + +Unserialised object: +object(DatePeriod)#1 (6) { + ["start"]=> + object(DateTimeImmutable)#2 (3) { + ["date"]=> + string(26) "1978-12-22 09:15:00.000000" + ["timezone_type"]=> + int(3) + ["timezone"]=> + string(16) "Europe/Amsterdam" + } + ["current"]=> + NULL + ["end"]=> + object(DateTimeImmutable)#8 (3) { + ["date"]=> + string(26) "2022-04-29 15:51:56.000000" + ["timezone_type"]=> + int(3) + ["timezone"]=> + string(13) "Europe/London" + } + ["interval"]=> + object(DateInterval)#9 (10) { + ["y"]=> + int(2) + ["m"]=> + int(6) + ["d"]=> + int(0) + ["h"]=> + int(0) + ["i"]=> + int(0) + ["s"]=> + int(0) + ["f"]=> + float(0) + ["invert"]=> + int(0) + ["days"]=> + bool(false) + ["from_string"]=> + bool(false) + } + ["recurrences"]=> + int(0) + ["include_start_date"]=> + bool(false) +} + + +Calling __serialize manually: +array(6) { + ["start"]=> + object(DateTimeImmutable)#10 (3) { + ["date"]=> + string(26) "1978-12-22 09:15:00.000000" + ["timezone_type"]=> + int(3) + ["timezone"]=> + string(16) "Europe/Amsterdam" + } + ["current"]=> + NULL + ["end"]=> + object(DateTimeImmutable)#11 (3) { + ["date"]=> + string(26) "2022-04-29 15:51:56.000000" + ["timezone_type"]=> + int(3) + ["timezone"]=> + string(13) "Europe/London" + } + ["interval"]=> + object(DateInterval)#12 (10) { + ["y"]=> + int(2) + ["m"]=> + int(6) + ["d"]=> + int(0) + ["h"]=> + int(0) + ["i"]=> + int(0) + ["s"]=> + int(0) + ["f"]=> + float(0) + ["invert"]=> + int(0) + ["days"]=> + bool(false) + ["from_string"]=> + bool(false) + } + ["recurrences"]=> + int(0) + ["include_start_date"]=> + bool(false) +} + + +Iterate of unserialised object: +1981-06-22T09:15:00+0200 +1983-12-22T09:15:00+0100 +1986-06-22T09:15:00+0200 +1988-12-22T09:15:00+0100 +1991-06-22T09:15:00+0200 +1993-12-22T09:15:00+0100 +1996-06-22T09:15:00+0200 +1998-12-22T09:15:00+0100 +2001-06-22T09:15:00+0200 +2003-12-22T09:15:00+0100 +2006-06-22T09:15:00+0200 +2008-12-22T09:15:00+0100 +2011-06-22T09:15:00+0200 +2013-12-22T09:15:00+0100 +2016-06-22T09:15:00+0200 +2018-12-22T09:15:00+0100 +2021-06-22T09:15:00+0200 diff --git a/ext/date/tests/DatePeriod_serialize-004.phpt b/ext/date/tests/DatePeriod_serialize-004.phpt new file mode 100644 index 0000000000000..fd62c5e2b7630 --- /dev/null +++ b/ext/date/tests/DatePeriod_serialize-004.phpt @@ -0,0 +1,207 @@ +--TEST-- +Test DatePeriod::__serialize and DatePeriod::__unserialize (start/recurrences) +--FILE-- +format(DateTime::ISO8601), "\n"; +} + +echo "\n\nSerialised object:\n"; +$s = serialize($p); +var_dump($s); + +echo "\n\nUnserialised object:\n"; +$e = unserialize($s); +var_dump($e); + +echo "\n\nCalling __serialize manually:\n"; +var_dump($p->__serialize()); + +echo "\n\nIterate of unserialised object:\n"; +foreach ( $p as $d ) +{ + echo $d->format(DateTime::ISO8601), "\n"; +} +?> +--EXPECTF-- +Original object: +object(DatePeriod)#3 (6) { + ["start"]=> + object(DateTimeImmutable)#4 (3) { + ["date"]=> + string(26) "1978-12-22 09:15:00.000000" + ["timezone_type"]=> + int(3) + ["timezone"]=> + string(16) "Europe/Amsterdam" + } + ["current"]=> + NULL + ["end"]=> + NULL + ["interval"]=> + object(DateInterval)#5 (10) { + ["y"]=> + int(0) + ["m"]=> + int(1) + ["d"]=> + int(0) + ["h"]=> + int(0) + ["i"]=> + int(0) + ["s"]=> + int(0) + ["f"]=> + float(0) + ["invert"]=> + int(0) + ["days"]=> + bool(false) + ["from_string"]=> + bool(false) + } + ["recurrences"]=> + int(7) + ["include_start_date"]=> + bool(false) +} + + +Iterate of object: +1979-01-01T09:15:00+0100 +1979-02-05T09:15:00+0100 +1979-03-05T09:15:00+0100 +1979-04-02T09:15:00+0200 +1979-05-07T09:15:00+0200 +1979-06-04T09:15:00+0200 +1979-07-02T09:15:00+0200 + + +Serialised object: +string(568) "O:10:"DatePeriod":6:{s:5:"start";O:17:"DateTimeImmutable":3:{s:4:"date";s:26:"1978-12-22 09:15:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:16:"Europe/Amsterdam";}s:7:"current";O:17:"DateTimeImmutable":3:{s:4:"date";s:26:"1979-08-06 09:15:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:16:"Europe/Amsterdam";}s:3:"end";N;s:8:"interval";O:12:"DateInterval":10:{s:1:"y";i:0;s:1:"m";i:1;s:1:"d";i:0;s:1:"h";i:0;s:1:"i";i:0;s:1:"s";i:0;s:1:"f";d:0;s:6:"invert";i:0;s:4:"days";b:0;s:11:"from_string";b:0;}s:11:"recurrences";i:7;s:18:"include_start_date";b:0;}" + + +Unserialised object: +object(DatePeriod)#1 (6) { + ["start"]=> + object(DateTimeImmutable)#6 (3) { + ["date"]=> + string(26) "1978-12-22 09:15:00.000000" + ["timezone_type"]=> + int(3) + ["timezone"]=> + string(16) "Europe/Amsterdam" + } + ["current"]=> + object(DateTimeImmutable)#8 (3) { + ["date"]=> + string(26) "1979-08-06 09:15:00.000000" + ["timezone_type"]=> + int(3) + ["timezone"]=> + string(16) "Europe/Amsterdam" + } + ["end"]=> + NULL + ["interval"]=> + object(DateInterval)#9 (10) { + ["y"]=> + int(0) + ["m"]=> + int(1) + ["d"]=> + int(0) + ["h"]=> + int(0) + ["i"]=> + int(0) + ["s"]=> + int(0) + ["f"]=> + float(0) + ["invert"]=> + int(0) + ["days"]=> + bool(false) + ["from_string"]=> + bool(false) + } + ["recurrences"]=> + int(7) + ["include_start_date"]=> + bool(false) +} + + +Calling __serialize manually: +array(6) { + ["start"]=> + object(DateTimeImmutable)#10 (3) { + ["date"]=> + string(26) "1978-12-22 09:15:00.000000" + ["timezone_type"]=> + int(3) + ["timezone"]=> + string(16) "Europe/Amsterdam" + } + ["current"]=> + object(DateTimeImmutable)#11 (3) { + ["date"]=> + string(26) "1979-08-06 09:15:00.000000" + ["timezone_type"]=> + int(3) + ["timezone"]=> + string(16) "Europe/Amsterdam" + } + ["end"]=> + NULL + ["interval"]=> + object(DateInterval)#12 (10) { + ["y"]=> + int(0) + ["m"]=> + int(1) + ["d"]=> + int(0) + ["h"]=> + int(0) + ["i"]=> + int(0) + ["s"]=> + int(0) + ["f"]=> + float(0) + ["invert"]=> + int(0) + ["days"]=> + bool(false) + ["from_string"]=> + bool(false) + } + ["recurrences"]=> + int(7) + ["include_start_date"]=> + bool(false) +} + + +Iterate of unserialised object: +1979-01-01T09:15:00+0100 +1979-02-05T09:15:00+0100 +1979-03-05T09:15:00+0100 +1979-04-02T09:15:00+0200 +1979-05-07T09:15:00+0200 +1979-06-04T09:15:00+0200 +1979-07-02T09:15:00+0200 diff --git a/ext/date/tests/bug53437.phpt b/ext/date/tests/bug53437_var0.phpt similarity index 99% rename from ext/date/tests/bug53437.phpt rename to ext/date/tests/bug53437_var0.phpt index ed885696bec11..36b6c317177f2 100644 --- a/ext/date/tests/bug53437.phpt +++ b/ext/date/tests/bug53437_var0.phpt @@ -1,5 +1,5 @@ --TEST-- -Bug #53437 (Crash when using unserialized DatePeriod instance), variation 1 +Bug #53437 (Crash when using unserialized DatePeriod instance), variation 0 --FILE-- __wakeup() +#0 [internal function]: DatePeriod->__unserialize(Array) #1 %sbug53437_var1.php(%d): unserialize('O:10:"DatePerio...') #2 {main} thrown in %sbug53437_var1.php on line %d