Add DatePeriod's __serialize and __unserialize methods (#8464)

This commit is contained in:
Derick Rethans 2022-05-03 22:06:17 +01:00 committed by GitHub
parent da857c94a4
commit d54bcbb43b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 857 additions and 13 deletions

View file

@ -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)
{

View file

@ -513,6 +513,10 @@ class DatePeriod implements IteratorAggregate
/** @tentative-return-type */
public function getRecurrences(): ?int {}
public function __serialize(): array;
public function __unserialize(array $data): void;
/** @tentative-return-type */
public function __wakeup(): void {}

View file

@ -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)

View file

@ -0,0 +1,160 @@
--TEST--
Test DatePeriod::__serialize and DatePeriod::__unserialize (ISO String)
--FILE--
<?php
date_default_timezone_set("Europe/London");
$d = new DatePeriod('R4/2012-07-01T00:00:00Z/P7D');
echo "Original object:\n";
var_dump($d);
echo "\n\nSerialised object:\n";
$s = serialize($d);
var_dump($s);
echo "\n\nUnserialised object:\n";
$e = unserialize($s);
var_dump($e);
echo "\n\nCalling __serialize manually:\n";
var_dump($d->__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)
}

View file

@ -0,0 +1,210 @@
--TEST--
Test DatePeriod::__serialize and DatePeriod::__unserialize (start/end)
--FILE--
<?php
date_default_timezone_set("Europe/London");
$s = new DateTimeImmutable("1978-12-22 09:15:00 Europe/Amsterdam");
$e = new DateTimeImmutable("2022-04-29 15:51:56 Europe/London");
$i = new DateInterval('P2Y6M');
$d = new DatePeriod($s, $i, $e);
echo "Original object:\n";
var_dump($d);
echo "\n\nSerialised object:\n";
$s = serialize($d);
var_dump($s);
echo "\n\nUnserialised object:\n";
$e = unserialize($s);
var_dump($e);
echo "\n\nCalling __serialize manually:\n";
var_dump($d->__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

View file

@ -0,0 +1,209 @@
--TEST--
Test DatePeriod::__serialize and DatePeriod::__unserialize (start/end)
--FILE--
<?php
date_default_timezone_set("Europe/London");
$s = new DateTimeImmutable("1978-12-22 09:15:00 Europe/Amsterdam");
$e = new DateTimeImmutable("2022-04-29 15:51:56 Europe/London");
$i = new DateInterval('P2Y6M');
$d = new DatePeriod($s, $i, $e, DatePeriod::EXCLUDE_START_DATE);
echo "Original object:\n";
var_dump($d);
echo "\n\nSerialised object:\n";
$s = serialize($d);
var_dump($s);
echo "\n\nUnserialised object:\n";
$e = unserialize($s);
var_dump($e);
echo "\n\nCalling __serialize manually:\n";
var_dump($d->__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

View file

@ -0,0 +1,207 @@
--TEST--
Test DatePeriod::__serialize and DatePeriod::__unserialize (start/recurrences)
--FILE--
<?php
date_default_timezone_set("Europe/London");
$s = new DateTimeImmutable("1978-12-22 09:15:00 Europe/Amsterdam");
$i = DateInterval::createFromDateString('first monday of next month');
$p = new DatePeriod($s, $i, 7, DatePeriod::EXCLUDE_START_DATE);
echo "Original object:\n";
var_dump($p);
echo "\n\nIterate of object:\n";
foreach ( $p as $d )
{
echo $d->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

View file

@ -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--
<?php
$dp = new DatePeriod(new DateTime('2010-01-01 UTC'), new DateInterval('P1D'), 2);

View file

@ -12,7 +12,7 @@ var_dump($dp);
--EXPECTF--
Fatal error: Uncaught Error: Invalid serialization data for DatePeriod object in %sbug53437_var1.php:%d
Stack trace:
#0 [internal function]: DatePeriod->__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