From 3be8b5f5cbdf70f407ec253b53c18266916c8312 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Thu, 14 Apr 2022 19:08:33 +0100 Subject: [PATCH 01/13] Remove fake properties from DateInterval --- ext/date/php_date.c | 44 +++++++----- ext/date/tests/DatePeriod_set_state.phpt | 16 +---- ext/date/tests/bug45682.phpt | 16 +---- ext/date/tests/bug48678.phpt | 14 ---- ext/date/tests/bug49081.phpt | 7 -- ext/date/tests/bug49778.phpt | 16 +---- ext/date/tests/bug52113.phpt | 87 ++---------------------- ext/date/tests/bug52738.phpt | 7 -- ext/date/tests/bug52808.phpt | 48 +------------ ext/date/tests/bug53437.phpt | 32 +-------- ext/date/tests/bug53437_var2.phpt | 34 +-------- ext/date/tests/bug53437_var4.phpt | 16 +---- ext/date/tests/bug53437_var5.phpt | 20 +----- ext/date/tests/bug53437_var6.phpt | 16 +---- ext/date/tests/bug60774.phpt | 14 ---- ext/date/tests/bug66545.phpt | 7 -- ext/date/tests/bug70153.phpt | 36 ++++++++-- ext/date/tests/bug71700.phpt | 18 +---- ext/date/tests/bug73091.phpt | 18 +---- ext/date/tests/bug74274.phpt | 7 -- ext/date/tests/bug74524.phpt | 7 -- ext/date/tests/bug77571.phpt | 7 -- ext/date/tests/bug78452.phpt | 18 +---- ext/date/tests/bug79015.phpt | 16 +---- ext/date/tests/date_diff1.phpt | 18 +---- ext/date/tests/date_time_fractions.phpt | 16 +---- 26 files changed, 91 insertions(+), 464 deletions(-) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 0a02a70f6266a..fb8e9c90ad1e9 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -2061,17 +2061,9 @@ static HashTable *date_object_get_gc_interval(zend_object *object, zval **table, return zend_std_get_properties(object); } /* }}} */ -static HashTable *date_object_get_properties_interval(zend_object *object) /* {{{ */ +static void date_interval_object_to_hash(php_interval_obj *intervalobj, HashTable *props, bool include_fakes) { - HashTable *props; zval zv; - php_interval_obj *intervalobj; - - intervalobj = php_interval_obj_from_obj(object); - props = zend_std_get_properties(object); - if (!intervalobj->initialized) { - return props; - } #define PHP_DATE_INTERVAL_ADD_PROPERTY(n,f) \ ZVAL_LONG(&zv, (zend_long)intervalobj->diff->f); \ @@ -2085,9 +2077,11 @@ static HashTable *date_object_get_properties_interval(zend_object *object) /* {{ PHP_DATE_INTERVAL_ADD_PROPERTY("s", s); ZVAL_DOUBLE(&zv, (double)intervalobj->diff->us / 1000000.0); zend_hash_str_update(props, "f", sizeof("f") - 1, &zv); - PHP_DATE_INTERVAL_ADD_PROPERTY("weekday", weekday); - PHP_DATE_INTERVAL_ADD_PROPERTY("weekday_behavior", weekday_behavior); - PHP_DATE_INTERVAL_ADD_PROPERTY("first_last_day_of", first_last_day_of); + if (include_fakes) { + PHP_DATE_INTERVAL_ADD_PROPERTY("weekday", weekday); + PHP_DATE_INTERVAL_ADD_PROPERTY("weekday_behavior", weekday_behavior); + PHP_DATE_INTERVAL_ADD_PROPERTY("first_last_day_of", first_last_day_of); + } PHP_DATE_INTERVAL_ADD_PROPERTY("invert", invert); if (intervalobj->diff->days != -99999) { PHP_DATE_INTERVAL_ADD_PROPERTY("days", days); @@ -2095,10 +2089,28 @@ static HashTable *date_object_get_properties_interval(zend_object *object) /* {{ ZVAL_FALSE(&zv); zend_hash_str_update(props, "days", sizeof("days")-1, &zv); } - PHP_DATE_INTERVAL_ADD_PROPERTY("special_type", special.type); - PHP_DATE_INTERVAL_ADD_PROPERTY("special_amount", special.amount); - PHP_DATE_INTERVAL_ADD_PROPERTY("have_weekday_relative", have_weekday_relative); - PHP_DATE_INTERVAL_ADD_PROPERTY("have_special_relative", have_special_relative); + if (include_fakes) { + PHP_DATE_INTERVAL_ADD_PROPERTY("special_type", special.type); + PHP_DATE_INTERVAL_ADD_PROPERTY("special_amount", special.amount); + PHP_DATE_INTERVAL_ADD_PROPERTY("have_weekday_relative", have_weekday_relative); + PHP_DATE_INTERVAL_ADD_PROPERTY("have_special_relative", have_special_relative); + } + +#undef PHP_DATE_INTERVAL_ADD_PROPERTY +} + +static HashTable *date_object_get_properties_interval(zend_object *object) /* {{{ */ +{ + HashTable *props; + php_interval_obj *intervalobj; + + intervalobj = php_interval_obj_from_obj(object); + props = zend_std_get_properties(object); + if (!intervalobj->initialized) { + return props; + } + + date_interval_object_to_hash(intervalobj, props, false); return props; } /* }}} */ diff --git a/ext/date/tests/DatePeriod_set_state.phpt b/ext/date/tests/DatePeriod_set_state.phpt index eaef2163cc8a3..eaf7d4dfe9e93 100644 --- a/ext/date/tests/DatePeriod_set_state.phpt +++ b/ext/date/tests/DatePeriod_set_state.phpt @@ -34,7 +34,7 @@ object(DatePeriod)#%d (6) { ["end"]=> NULL ["interval"]=> - object(DateInterval)#%d (16) { + object(DateInterval)#%d (%d) { ["y"]=> int(0) ["m"]=> @@ -49,24 +49,10 @@ object(DatePeriod)#%d (6) { int(0) ["f"]=> float(0) - ["weekday"]=> - int(0) - ["weekday_behavior"]=> - int(0) - ["first_last_day_of"]=> - int(0) ["invert"]=> int(0) ["days"]=> bool(false) - ["special_type"]=> - int(0) - ["special_amount"]=> - int(0) - ["have_weekday_relative"]=> - int(0) - ["have_special_relative"]=> - int(0) } ["recurrences"]=> int(25) diff --git a/ext/date/tests/bug45682.phpt b/ext/date/tests/bug45682.phpt index 636381dcfeda0..7568fd07d9bca 100644 --- a/ext/date/tests/bug45682.phpt +++ b/ext/date/tests/bug45682.phpt @@ -13,7 +13,7 @@ $diff = date_diff($date, $other); var_dump($diff); ?> --EXPECTF-- -object(DateInterval)#%d (16) { +object(DateInterval)#%d (%d) { ["y"]=> int(0) ["m"]=> @@ -28,22 +28,8 @@ object(DateInterval)#%d (16) { int(0) ["f"]=> float(0) - ["weekday"]=> - int(0) - ["weekday_behavior"]=> - int(0) - ["first_last_day_of"]=> - int(0) ["invert"]=> int(0) ["days"]=> int(3) - ["special_type"]=> - int(0) - ["special_amount"]=> - int(0) - ["have_weekday_relative"]=> - int(0) - ["have_special_relative"]=> - int(0) } diff --git a/ext/date/tests/bug48678.phpt b/ext/date/tests/bug48678.phpt index 9c1cecd2df780..df1571a829648 100644 --- a/ext/date/tests/bug48678.phpt +++ b/ext/date/tests/bug48678.phpt @@ -17,15 +17,8 @@ DateInterval Object [i] => 30 [s] => 5 [f] => 0 - [weekday] => 0 - [weekday_behavior] => 0 - [first_last_day_of] => 0 [invert] => 0 [days] => - [special_type] => 0 - [special_amount] => 0 - [have_weekday_relative] => 0 - [have_special_relative] => 0 ) DateInterval Object ( @@ -36,13 +29,6 @@ DateInterval Object [i] => 30 [s] => 5 [f] => 0 - [weekday] => 0 - [weekday_behavior] => 0 - [first_last_day_of] => 0 [invert] => 0 [days] => - [special_type] => 0 - [special_amount] => 0 - [have_weekday_relative] => 0 - [have_special_relative] => 0 ) diff --git a/ext/date/tests/bug49081.phpt b/ext/date/tests/bug49081.phpt index b5d17a6c264b6..c29075e17cea9 100644 --- a/ext/date/tests/bug49081.phpt +++ b/ext/date/tests/bug49081.phpt @@ -18,13 +18,6 @@ DateInterval Object [i] => 0 [s] => 0 [f] => 0 - [weekday] => 0 - [weekday_behavior] => 0 - [first_last_day_of] => 0 [invert] => 0 [days] => 30 - [special_type] => 0 - [special_amount] => 0 - [have_weekday_relative] => 0 - [have_special_relative] => 0 ) diff --git a/ext/date/tests/bug49778.phpt b/ext/date/tests/bug49778.phpt index 56ce135179222..cce69f8e7748f 100644 --- a/ext/date/tests/bug49778.phpt +++ b/ext/date/tests/bug49778.phpt @@ -8,7 +8,7 @@ echo $i->format("%d"), "\n"; echo $i->format("%a"), "\n"; ?> --EXPECTF-- -object(DateInterval)#%d (16) { +object(DateInterval)#%d (%d) { ["y"]=> int(0) ["m"]=> @@ -23,24 +23,10 @@ object(DateInterval)#%d (16) { int(0) ["f"]=> float(0) - ["weekday"]=> - int(0) - ["weekday_behavior"]=> - int(0) - ["first_last_day_of"]=> - int(0) ["invert"]=> int(0) ["days"]=> bool(false) - ["special_type"]=> - int(0) - ["special_amount"]=> - int(0) - ["have_weekday_relative"]=> - int(0) - ["have_special_relative"]=> - int(0) } 7 (unknown) diff --git a/ext/date/tests/bug52113.phpt b/ext/date/tests/bug52113.phpt index 84cd1b5210157..c6e280cd40668 100644 --- a/ext/date/tests/bug52113.phpt +++ b/ext/date/tests/bug52113.phpt @@ -33,7 +33,7 @@ var_dump($unser, $p); ?> --EXPECTF-- -object(DateInterval)#%d (16) { +object(DateInterval)#%d (%d) { ["y"]=> int(0) ["m"]=> @@ -48,24 +48,10 @@ object(DateInterval)#%d (16) { int(0) ["f"]=> float(0) - ["weekday"]=> - int(0) - ["weekday_behavior"]=> - int(0) - ["first_last_day_of"]=> - int(0) ["invert"]=> int(0) ["days"]=> int(0) - ["special_type"]=> - int(0) - ["special_amount"]=> - int(0) - ["have_weekday_relative"]=> - int(0) - ["have_special_relative"]=> - int(0) } string(332) "O:12:"DateInterval":16:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:0;s:1:"h";i:4;s:1:"i";i:0;s:1:"s";i:0;s:1:"f";d:0;s:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:6:"invert";i:0;s:4:"days";i:0;s:12:"special_type";i:0;s:14:"special_amount";i:0;s:21:"have_weekday_relative";i:0;s:21:"have_special_relative";i:0;}" \DateInterval::__set_state(array( @@ -76,16 +62,9 @@ string(332) "O:12:"DateInterval":16:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:0;s:1:"h" 'i' => 0, 's' => 0, 'f' => 0.0, - 'weekday' => 0, - 'weekday_behavior' => 0, - 'first_last_day_of' => 0, 'invert' => 0, 'days' => 0, - 'special_type' => 0, - 'special_amount' => 0, - 'have_weekday_relative' => 0, - 'have_special_relative' => 0, -))object(DateInterval)#%d (16) { +))object(DateInterval)#%d (%d) { ["y"]=> int(0) ["m"]=> @@ -100,24 +79,10 @@ string(332) "O:12:"DateInterval":16:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:0;s:1:"h" int(0) ["f"]=> float(0) - ["weekday"]=> - int(0) - ["weekday_behavior"]=> - int(0) - ["first_last_day_of"]=> - int(0) ["invert"]=> int(0) ["days"]=> int(0) - ["special_type"]=> - int(0) - ["special_amount"]=> - int(0) - ["have_weekday_relative"]=> - int(0) - ["have_special_relative"]=> - int(0) } object(DatePeriod)#%d (6) { ["start"]=> @@ -134,7 +99,7 @@ object(DatePeriod)#%d (6) { ["end"]=> NULL ["interval"]=> - object(DateInterval)#%d (16) { + object(DateInterval)#%d (%d) { ["y"]=> int(0) ["m"]=> @@ -149,31 +114,17 @@ object(DatePeriod)#%d (6) { int(0) ["f"]=> float(0) - ["weekday"]=> - int(0) - ["weekday_behavior"]=> - int(0) - ["first_last_day_of"]=> - int(0) ["invert"]=> int(0) ["days"]=> int(0) - ["special_type"]=> - int(0) - ["special_amount"]=> - int(0) - ["have_weekday_relative"]=> - int(0) - ["have_special_relative"]=> - int(0) } ["recurrences"]=> int(3) ["include_start_date"]=> bool(true) } -object(DateInterval)#%d (16) { +object(DateInterval)#%d (%d) { ["y"]=> int(7) ["m"]=> @@ -188,24 +139,10 @@ object(DateInterval)#%d (16) { int(2) ["f"]=> float(0.876543) - ["weekday"]=> - int(-1) - ["weekday_behavior"]=> - int(-1) - ["first_last_day_of"]=> - int(-1) ["invert"]=> int(1) ["days"]=> int(2400) - ["special_type"]=> - int(0) - ["special_amount"]=> - int(-1) - ["have_weekday_relative"]=> - int(0) - ["have_special_relative"]=> - int(0) } object(DatePeriod)#%d (6) { ["start"]=> @@ -222,7 +159,7 @@ object(DatePeriod)#%d (6) { ["end"]=> NULL ["interval"]=> - object(DateInterval)#%d (16) { + object(DateInterval)#%d (%d) { ["y"]=> int(0) ["m"]=> @@ -237,24 +174,10 @@ object(DatePeriod)#%d (6) { int(0) ["f"]=> float(0) - ["weekday"]=> - int(0) - ["weekday_behavior"]=> - int(0) - ["first_last_day_of"]=> - int(0) ["invert"]=> int(0) ["days"]=> int(0) - ["special_type"]=> - int(0) - ["special_amount"]=> - int(0) - ["have_weekday_relative"]=> - int(0) - ["have_special_relative"]=> - int(0) } ["recurrences"]=> int(3) diff --git a/ext/date/tests/bug52738.phpt b/ext/date/tests/bug52738.phpt index 4f51fc38988a4..46be78af1943c 100644 --- a/ext/date/tests/bug52738.phpt +++ b/ext/date/tests/bug52738.phpt @@ -29,13 +29,6 @@ di Object [i] => 0 [s] => 0 [f] => 0 - [weekday] => 0 - [weekday_behavior] => 0 - [first_last_day_of] => 0 [invert] => 0 [days] => - [special_type] => 0 - [special_amount] => 0 - [have_weekday_relative] => 0 - [have_special_relative] => 0 ) diff --git a/ext/date/tests/bug52808.phpt b/ext/date/tests/bug52808.phpt index c0ab817bcc84b..190d5184393df 100644 --- a/ext/date/tests/bug52808.phpt +++ b/ext/date/tests/bug52808.phpt @@ -25,7 +25,7 @@ foreach($intervals as $iv) { echo "==DONE==\n"; ?> --EXPECTF-- -object(DateInterval)#%d (16) { +object(DateInterval)#%d (%d) { ["y"]=> int(1) ["m"]=> @@ -40,26 +40,12 @@ object(DateInterval)#%d (16) { int(0) ["f"]=> float(0) - ["weekday"]=> - int(0) - ["weekday_behavior"]=> - int(0) - ["first_last_day_of"]=> - int(0) ["invert"]=> int(1) ["days"]=> int(437) - ["special_type"]=> - int(0) - ["special_amount"]=> - int(0) - ["have_weekday_relative"]=> - int(0) - ["have_special_relative"]=> - int(0) } -object(DateInterval)#%d (16) { +object(DateInterval)#%d (%d) { ["y"]=> int(0) ["m"]=> @@ -74,26 +60,12 @@ object(DateInterval)#%d (16) { int(0) ["f"]=> float(0) - ["weekday"]=> - int(0) - ["weekday_behavior"]=> - int(0) - ["first_last_day_of"]=> - int(0) ["invert"]=> int(0) ["days"]=> int(294) - ["special_type"]=> - int(0) - ["special_amount"]=> - int(0) - ["have_weekday_relative"]=> - int(0) - ["have_special_relative"]=> - int(0) } -object(DateInterval)#%d (16) { +object(DateInterval)#%d (%d) { ["y"]=> int(0) ["m"]=> @@ -108,24 +80,10 @@ object(DateInterval)#%d (16) { int(0) ["f"]=> float(0) - ["weekday"]=> - int(0) - ["weekday_behavior"]=> - int(0) - ["first_last_day_of"]=> - int(0) ["invert"]=> int(0) ["days"]=> int(294) - ["special_type"]=> - int(0) - ["special_amount"]=> - int(0) - ["have_weekday_relative"]=> - int(0) - ["have_special_relative"]=> - int(0) } Failed to parse interval (2007-05-11T15:30:00Z/) Failed to parse interval (2007-05-11T15:30:00Z) diff --git a/ext/date/tests/bug53437.phpt b/ext/date/tests/bug53437.phpt index f19f073aa9430..349fd5b39f0b8 100644 --- a/ext/date/tests/bug53437.phpt +++ b/ext/date/tests/bug53437.phpt @@ -50,7 +50,7 @@ object(DatePeriod)#%d (6) { ["end"]=> NULL ["interval"]=> - object(DateInterval)#%d (16) { + object(DateInterval)#%d (%d) { ["y"]=> int(0) ["m"]=> @@ -65,24 +65,10 @@ object(DatePeriod)#%d (6) { int(0) ["f"]=> float(0) - ["weekday"]=> - int(0) - ["weekday_behavior"]=> - int(0) - ["first_last_day_of"]=> - int(0) ["invert"]=> int(0) ["days"]=> bool(false) - ["special_type"]=> - int(0) - ["special_amount"]=> - int(0) - ["have_weekday_relative"]=> - int(0) - ["have_special_relative"]=> - int(0) } ["recurrences"]=> int(3) @@ -111,7 +97,7 @@ object(DatePeriod)#%d (6) { ["end"]=> NULL ["interval"]=> - object(DateInterval)#%d (16) { + object(DateInterval)#%d (%d) { ["y"]=> int(0) ["m"]=> @@ -126,24 +112,10 @@ object(DatePeriod)#%d (6) { int(0) ["f"]=> float(0) - ["weekday"]=> - int(0) - ["weekday_behavior"]=> - int(0) - ["first_last_day_of"]=> - int(0) ["invert"]=> int(0) ["days"]=> bool(false) - ["special_type"]=> - int(0) - ["special_amount"]=> - int(0) - ["have_weekday_relative"]=> - int(0) - ["have_special_relative"]=> - int(0) } ["recurrences"]=> int(3) diff --git a/ext/date/tests/bug53437_var2.phpt b/ext/date/tests/bug53437_var2.phpt index 7a87b38421a50..23527684f39ef 100644 --- a/ext/date/tests/bug53437_var2.phpt +++ b/ext/date/tests/bug53437_var2.phpt @@ -11,8 +11,8 @@ $di1 = unserialize($s); var_dump($di0, $di1); ?> ---EXPECT-- -object(DateInterval)#1 (16) { +--EXPECTF-- +object(DateInterval)#1 (%d) { ["y"]=> int(2) ["m"]=> @@ -27,26 +27,12 @@ object(DateInterval)#1 (16) { int(0) ["f"]=> float(0) - ["weekday"]=> - int(0) - ["weekday_behavior"]=> - int(0) - ["first_last_day_of"]=> - int(0) ["invert"]=> int(0) ["days"]=> bool(false) - ["special_type"]=> - int(0) - ["special_amount"]=> - int(0) - ["have_weekday_relative"]=> - int(0) - ["have_special_relative"]=> - int(0) } -object(DateInterval)#2 (16) { +object(DateInterval)#2 (%d) { ["y"]=> int(2) ["m"]=> @@ -61,22 +47,8 @@ object(DateInterval)#2 (16) { int(0) ["f"]=> float(0) - ["weekday"]=> - int(0) - ["weekday_behavior"]=> - int(0) - ["first_last_day_of"]=> - int(0) ["invert"]=> int(0) ["days"]=> bool(false) - ["special_type"]=> - int(0) - ["special_amount"]=> - int(0) - ["have_weekday_relative"]=> - int(0) - ["have_special_relative"]=> - int(0) } diff --git a/ext/date/tests/bug53437_var4.phpt b/ext/date/tests/bug53437_var4.phpt index b53483ab7fa2b..05defd24125e4 100644 --- a/ext/date/tests/bug53437_var4.phpt +++ b/ext/date/tests/bug53437_var4.phpt @@ -21,7 +21,7 @@ var_dump($df, ?> --EXPECTF-- -object(DateInterval)#%d (16) { +object(DateInterval)#%d (%d) { ["y"]=> int(0) ["m"]=> @@ -36,24 +36,10 @@ object(DateInterval)#%d (16) { int(0) ["f"]=> float(0) - ["weekday"]=> - int(0) - ["weekday_behavior"]=> - int(0) - ["first_last_day_of"]=> - int(0) ["invert"]=> int(0) ["days"]=> int(2) - ["special_type"]=> - int(0) - ["special_amount"]=> - int(0) - ["have_weekday_relative"]=> - int(0) - ["have_special_relative"]=> - int(0) } int(0) int(0) diff --git a/ext/date/tests/bug53437_var5.phpt b/ext/date/tests/bug53437_var5.phpt index 55bba9ed59d8f..61ebffe5237dd 100644 --- a/ext/date/tests/bug53437_var5.phpt +++ b/ext/date/tests/bug53437_var5.phpt @@ -11,7 +11,7 @@ var_dump($di); ?> --EXPECTF-- -object(DateInterval)#%d (16) { +object(DateInterval)#%d (%d) { ["y"]=> int(2) ["m"]=> @@ -24,24 +24,10 @@ object(DateInterval)#%d (16) { int(8) ["s"]=> int(0) - ["weekday"]=> - int(10) - ["weekday_behavior"]=> - int(10) - ["first_last_day_of"]=> - int(0) + ["f"]=> + float(0) ["invert"]=> int(0) ["days"]=> int(0) - ["special_type"]=> - int(0) - ["special_amount"]=> - int(9223372036854775807) - ["have_weekday_relative"]=> - int(9) - ["have_special_relative"]=> - int(0) - ["f"]=> - float(0) } diff --git a/ext/date/tests/bug53437_var6.phpt b/ext/date/tests/bug53437_var6.phpt index f5ff22c4a4612..e03a28ec6b4c9 100644 --- a/ext/date/tests/bug53437_var6.phpt +++ b/ext/date/tests/bug53437_var6.phpt @@ -11,7 +11,7 @@ var_dump($di); ?> --EXPECTF-- -object(DateInterval)#%d (16) { +object(DateInterval)#%d (%d) { ["y"]=> int(2) ["m"]=> @@ -26,22 +26,8 @@ object(DateInterval)#%d (16) { int(0) ["f"]=> float(0.123654) - ["weekday"]=> - int(10) - ["weekday_behavior"]=> - int(10) - ["first_last_day_of"]=> - int(0) ["invert"]=> int(0) ["days"]=> int(0) - ["special_type"]=> - int(0) - ["special_amount"]=> - int(9223372036854775807) - ["have_weekday_relative"]=> - int(9) - ["have_special_relative"]=> - int(0) } diff --git a/ext/date/tests/bug60774.phpt b/ext/date/tests/bug60774.phpt index 0a9c4223c37c3..6349ee0f37348 100644 --- a/ext/date/tests/bug60774.phpt +++ b/ext/date/tests/bug60774.phpt @@ -23,24 +23,10 @@ object(DateInterval)#1 (%d) { int(0) ["f"]=> float(0) - ["weekday"]=> - int(0) - ["weekday_behavior"]=> - int(0) - ["first_last_day_of"]=> - int(0) ["invert"]=> int(0) ["days"]=> bool(false) - ["special_type"]=> - int(0) - ["special_amount"]=> - int(0) - ["have_weekday_relative"]=> - int(0) - ["have_special_relative"]=> - int(0) } 2 (unknown) diff --git a/ext/date/tests/bug66545.phpt b/ext/date/tests/bug66545.phpt index 276c6d5f67581..85518920f433a 100644 --- a/ext/date/tests/bug66545.phpt +++ b/ext/date/tests/bug66545.phpt @@ -25,13 +25,6 @@ DateInterval Object [i] => 59 [s] => 59 [f] => 0 - [weekday] => 0 - [weekday_behavior] => 0 - [first_last_day_of] => 0 [invert] => 0 [days] => 14 - [special_type] => 0 - [special_amount] => 0 - [have_weekday_relative] => 0 - [have_special_relative] => 0 ) diff --git a/ext/date/tests/bug70153.phpt b/ext/date/tests/bug70153.phpt index 5b965207fc27d..ca82dba980cc9 100644 --- a/ext/date/tests/bug70153.phpt +++ b/ext/date/tests/bug70153.phpt @@ -3,12 +3,40 @@ Bug #70153 (\DateInterval incorrectly unserialized) --FILE-- days, $i2->days); -var_dump($i2->special_amount, $i2->special_amount); ?> --EXPECT-- +DateInterval Object +( + [y] => 0 + [m] => 1 + [d] => 0 + [h] => 0 + [i] => 0 + [s] => 0 + [f] => 0 + [invert] => 0 + [days] => +) +O:12:"DateInterval":16:{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:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:6:"invert";i:0;s:4:"days";b:0;s:12:"special_type";i:0;s:14:"special_amount";i:0;s:21:"have_weekday_relative";i:0;s:21:"have_special_relative";i:0;}DateInterval Object +( + [y] => 0 + [m] => 1 + [d] => 0 + [h] => 0 + [i] => 0 + [s] => 0 + [f] => 0 + [invert] => 0 + [days] => +) bool(false) bool(false) -int(0) -int(0) diff --git a/ext/date/tests/bug71700.phpt b/ext/date/tests/bug71700.phpt index 53a6f9db20992..8a9ec3992fc02 100644 --- a/ext/date/tests/bug71700.phpt +++ b/ext/date/tests/bug71700.phpt @@ -11,8 +11,8 @@ $diff = date_diff($date1, $date2, true); var_dump($diff); ?> ---EXPECT-- -object(DateInterval)#3 (16) { +--EXPECTF-- +object(DateInterval)#3 (%d) { ["y"]=> int(0) ["m"]=> @@ -27,22 +27,8 @@ object(DateInterval)#3 (16) { int(0) ["f"]=> float(0) - ["weekday"]=> - int(0) - ["weekday_behavior"]=> - int(0) - ["first_last_day_of"]=> - int(0) ["invert"]=> int(0) ["days"]=> int(30) - ["special_type"]=> - int(0) - ["special_amount"]=> - int(0) - ["have_weekday_relative"]=> - int(0) - ["have_special_relative"]=> - int(0) } diff --git a/ext/date/tests/bug73091.phpt b/ext/date/tests/bug73091.phpt index 918170d823fb1..b75951d036e4c 100644 --- a/ext/date/tests/bug73091.phpt +++ b/ext/date/tests/bug73091.phpt @@ -12,9 +12,7 @@ class foo { var_dump(unserialize('O:12:"DateInterval":1:{s:4:"days";O:3:"foo":0:{}}')); ?> --EXPECTF-- -object(DateInterval)#%d (16) { - ["days"]=> - int(-1) +object(DateInterval)#%d (%d) { ["y"]=> int(-1) ["m"]=> @@ -29,20 +27,8 @@ object(DateInterval)#%d (16) { int(-1) ["f"]=> float(0) - ["weekday"]=> - int(-1) - ["weekday_behavior"]=> - int(-1) - ["first_last_day_of"]=> - int(-1) ["invert"]=> int(0) - ["special_type"]=> - int(0) - ["special_amount"]=> + ["days"]=> int(-1) - ["have_weekday_relative"]=> - int(0) - ["have_special_relative"]=> - int(0) } diff --git a/ext/date/tests/bug74274.phpt b/ext/date/tests/bug74274.phpt index e03d40cf88da7..f5b7f6595454c 100644 --- a/ext/date/tests/bug74274.phpt +++ b/ext/date/tests/bug74274.phpt @@ -18,13 +18,6 @@ DateInterval Object [i] => 0 [s] => 0 [f] => 0 - [weekday] => 0 - [weekday_behavior] => 0 - [first_last_day_of] => 0 [invert] => 0 [days] => 1 - [special_type] => 0 - [special_amount] => 0 - [have_weekday_relative] => 0 - [have_special_relative] => 0 ) diff --git a/ext/date/tests/bug74524.phpt b/ext/date/tests/bug74524.phpt index f49a5340185e9..40cca02108858 100644 --- a/ext/date/tests/bug74524.phpt +++ b/ext/date/tests/bug74524.phpt @@ -20,13 +20,6 @@ DateInterval Object [i] => 36 [s] => 10 [f] => 0.920541 - [weekday] => 0 - [weekday_behavior] => 0 - [first_last_day_of] => 0 [invert] => 1 [days] => 227 - [special_type] => 0 - [special_amount] => 0 - [have_weekday_relative] => 0 - [have_special_relative] => 0 ) diff --git a/ext/date/tests/bug77571.phpt b/ext/date/tests/bug77571.phpt index f6a5b55dab0f6..673b943256e47 100644 --- a/ext/date/tests/bug77571.phpt +++ b/ext/date/tests/bug77571.phpt @@ -21,13 +21,6 @@ DateInterval Object [i] => 0 [s] => 0 [f] => 0 - [weekday] => 0 - [weekday_behavior] => 0 - [first_last_day_of] => 0 [invert] => 0 [days] => 35 - [special_type] => 0 - [special_amount] => 0 - [have_weekday_relative] => 0 - [have_special_relative] => 0 ) diff --git a/ext/date/tests/bug78452.phpt b/ext/date/tests/bug78452.phpt index a4b095de03abb..dec40fafea306 100644 --- a/ext/date/tests/bug78452.phpt +++ b/ext/date/tests/bug78452.phpt @@ -7,8 +7,8 @@ $date1 = new \DateTime('2019-09-24 11:47:24'); $date2 = new \DateTime('2019-08-21 12:47:24'); var_dump($date1->diff($date2)); ?> ---EXPECT-- -object(DateInterval)#3 (16) { +--EXPECTF-- +object(DateInterval)#3 (%d) { ["y"]=> int(0) ["m"]=> @@ -23,22 +23,8 @@ object(DateInterval)#3 (16) { int(0) ["f"]=> float(0) - ["weekday"]=> - int(0) - ["weekday_behavior"]=> - int(0) - ["first_last_day_of"]=> - int(0) ["invert"]=> int(1) ["days"]=> int(33) - ["special_type"]=> - int(0) - ["special_amount"]=> - int(0) - ["have_weekday_relative"]=> - int(0) - ["have_special_relative"]=> - int(0) } diff --git a/ext/date/tests/bug79015.phpt b/ext/date/tests/bug79015.phpt index 9d752dee7221e..2059658e1e05c 100644 --- a/ext/date/tests/bug79015.phpt +++ b/ext/date/tests/bug79015.phpt @@ -6,7 +6,7 @@ $payload = 'O:12:"DateInterval":16:{s:1:"y";i:1;s:1:"m";i:0;s:1:"d";i:4;s:1:"h"; var_dump(unserialize($payload)); ?> --EXPECTF-- -object(DateInterval)#%d (16) { +object(DateInterval)#%d (%d) { ["y"]=> int(1) ["m"]=> @@ -21,22 +21,8 @@ object(DateInterval)#%d (16) { int(0) ["f"]=> float(%f) - ["weekday"]=> - int(0) - ["weekday_behavior"]=> - int(0) - ["first_last_day_of"]=> - int(0) ["invert"]=> int(0) ["days"]=> bool(false) - ["special_type"]=> - int(0) - ["special_amount"]=> - int(0) - ["have_weekday_relative"]=> - int(0) - ["have_special_relative"]=> - int(0) } diff --git a/ext/date/tests/date_diff1.phpt b/ext/date/tests/date_diff1.phpt index 2b73eae6a8cc3..e3556590f8e3e 100644 --- a/ext/date/tests/date_diff1.phpt +++ b/ext/date/tests/date_diff1.phpt @@ -28,7 +28,7 @@ object(DateTime)#2 (3) { ["timezone"]=> string(3) "EDT" } -object(DateInterval)#%d (16) { +object(DateInterval)#%d (%d) { ["y"]=> int(0) ["m"]=> @@ -36,29 +36,15 @@ object(DateInterval)#%d (16) { ["d"]=> int(2) ["h"]=> - int(16) + int(%d) ["i"]=> int(19) ["s"]=> int(40) ["f"]=> float(0) - ["weekday"]=> - int(0) - ["weekday_behavior"]=> - int(0) - ["first_last_day_of"]=> - int(0) ["invert"]=> int(0) ["days"]=> int(33) - ["special_type"]=> - int(0) - ["special_amount"]=> - int(0) - ["have_weekday_relative"]=> - int(0) - ["have_special_relative"]=> - int(0) } diff --git a/ext/date/tests/date_time_fractions.phpt b/ext/date/tests/date_time_fractions.phpt index 29f7cd0d14103..215b7c92333b2 100644 --- a/ext/date/tests/date_time_fractions.phpt +++ b/ext/date/tests/date_time_fractions.phpt @@ -58,7 +58,7 @@ microseconds = true 2016-10-02 00:00:00.000000 2016-10-03 12:00:00.000000 2016-10-17 12:47:18.081921 -object(DateInterval)#%d (16) { +object(DateInterval)#%d (%d) { ["y"]=> int(0) ["m"]=> @@ -73,24 +73,10 @@ object(DateInterval)#%d (16) { int(0) ["f"]=> float(0.378189) - ["weekday"]=> - int(0) - ["weekday_behavior"]=> - int(0) - ["first_last_day_of"]=> - int(0) ["invert"]=> int(0) ["days"]=> int(0) - ["special_type"]=> - int(0) - ["special_amount"]=> - int(0) - ["have_weekday_relative"]=> - int(0) - ["have_special_relative"]=> - int(0) } 2016-10-03 13:20:06.724934 2016-10-03 13:20:07.103123 From f869a546e7b44d9361e0632f4f2509becb6f3fc5 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Fri, 15 Apr 2022 10:53:16 +0100 Subject: [PATCH 02/13] Add DateInterval's __serialize and __unserialize methods --- ext/date/php_date.c | 38 +++++++++++++++++++++++++++++++++++++ ext/date/php_date.stub.php | 4 ++++ ext/date/php_date_arginfo.h | 10 +++++++++- 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index fb8e9c90ad1e9..636e4f874e9fc 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -4204,6 +4204,44 @@ PHP_METHOD(DateInterval, __set_state) } /* }}} */ +/* {{{ */ +PHP_METHOD(DateInterval, __serialize) +{ + zval *object = ZEND_THIS; + php_interval_obj *intervalobj; + HashTable *myht; + + ZEND_PARSE_PARAMETERS_NONE(); + + intervalobj = Z_PHPINTERVAL_P(object); + DATE_CHECK_INITIALIZED(intervalobj->initialized, DateInterval); + + array_init(return_value); + myht = Z_ARRVAL_P(return_value); + date_interval_object_to_hash(intervalobj, myht, true); +} +/* }}} */ + + +/* {{{ */ +PHP_METHOD(DateInterval, __unserialize) +{ + zval *object = ZEND_THIS; + php_interval_obj *intervalobj; + zval *array; + HashTable *myht; + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(array) + ZEND_PARSE_PARAMETERS_END(); + + intervalobj = Z_PHPINTERVAL_P(object); + myht = Z_ARRVAL_P(array); + + php_date_interval_initialize_from_hash(&object, &intervalobj, myht); +} +/* }}} */ + /* {{{ */ PHP_METHOD(DateInterval, __wakeup) { diff --git a/ext/date/php_date.stub.php b/ext/date/php_date.stub.php index ea3aba7c7b361..5cb435647c946 100644 --- a/ext/date/php_date.stub.php +++ b/ext/date/php_date.stub.php @@ -480,6 +480,10 @@ public static function createFromDateString(string $datetime): DateInterval|fals */ public function format(string $format): string {} + 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 367674f5e4f43..722f38b1793d6 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: a157de6bca4bcf5a9ddace9e81ef700f132b4dda */ + * Stub hash: 4845891ab3872f292438de639953e2022f849125 */ 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) @@ -451,6 +451,10 @@ ZEND_END_ARG_INFO() #define arginfo_class_DateInterval_format arginfo_class_DateTimeInterface_format +#define arginfo_class_DateInterval___serialize arginfo_timezone_abbreviations_list + +#define arginfo_class_DateInterval___unserialize arginfo_class_DateTimeInterface___unserialize + #define arginfo_class_DateInterval___wakeup arginfo_class_DateTimeInterface___wakeup ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(arginfo_class_DateInterval___set_state, 0, 1, DateInterval, 0) @@ -562,6 +566,8 @@ ZEND_METHOD(DateTimeZone, __unserialize); ZEND_METHOD(DateTimeZone, __wakeup); ZEND_METHOD(DateTimeZone, __set_state); ZEND_METHOD(DateInterval, __construct); +ZEND_METHOD(DateInterval, __serialize); +ZEND_METHOD(DateInterval, __unserialize); ZEND_METHOD(DateInterval, __wakeup); ZEND_METHOD(DateInterval, __set_state); ZEND_METHOD(DatePeriod, __construct); @@ -714,6 +720,8 @@ static const zend_function_entry class_DateInterval_methods[] = { ZEND_ME(DateInterval, __construct, arginfo_class_DateInterval___construct, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(createFromDateString, date_interval_create_from_date_string, arginfo_class_DateInterval_createFromDateString, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) ZEND_ME_MAPPING(format, date_interval_format, arginfo_class_DateInterval_format, ZEND_ACC_PUBLIC) + ZEND_ME(DateInterval, __serialize, arginfo_class_DateInterval___serialize, ZEND_ACC_PUBLIC) + ZEND_ME(DateInterval, __unserialize, arginfo_class_DateInterval___unserialize, ZEND_ACC_PUBLIC) ZEND_ME(DateInterval, __wakeup, arginfo_class_DateInterval___wakeup, ZEND_ACC_PUBLIC) ZEND_ME(DateInterval, __set_state, arginfo_class_DateInterval___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) ZEND_FE_END From 76e852e7e8ba20901d33ccf405ba85e914870768 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Fri, 15 Apr 2022 10:54:42 +0100 Subject: [PATCH 03/13] Fixed memory leak with manual calls to DateInterval::__unserialize --- ext/date/php_date.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 636e4f874e9fc..7dc885d56aae2 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -4104,6 +4104,12 @@ PHP_METHOD(DateInterval, __construct) static void php_date_interval_initialize_from_hash(zval **return_value, php_interval_obj **intobj, HashTable *myht) /* {{{ */ { + /* If ->diff is already set, then we need to free it first */ + if ((*intobj)->diff) { + timelib_rel_time_dtor((*intobj)->diff); + } + + /* Set new value */ (*intobj)->diff = timelib_rel_time_ctor(); #define PHP_DATE_INTERVAL_READ_PROPERTY(element, member, itype, def) \ From f4e5010aa995862b60473376c7242422b53b8191 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Fri, 15 Apr 2022 10:55:39 +0100 Subject: [PATCH 04/13] Show the 'have_special_relative' property in var_dumps, and disallow serialization if set --- ext/date/php_date.c | 7 ++++++- ext/date/tests/DatePeriod_set_state.phpt | 2 ++ ext/date/tests/bug45682.phpt | 2 ++ ext/date/tests/bug48678.phpt | 2 ++ ext/date/tests/bug49081.phpt | 1 + ext/date/tests/bug49778.phpt | 2 ++ ext/date/tests/bug52113.phpt | 11 +++++++++++ ext/date/tests/bug52738.phpt | 1 + ext/date/tests/bug52808.phpt | 6 ++++++ ext/date/tests/bug53437.phpt | 4 ++++ ext/date/tests/bug53437_var2.phpt | 6 +++++- ext/date/tests/bug53437_var4.phpt | 2 ++ ext/date/tests/bug53437_var5.phpt | 4 +++- ext/date/tests/bug53437_var6.phpt | 4 +++- ext/date/tests/bug60774.phpt | 2 ++ ext/date/tests/bug66545.phpt | 1 + ext/date/tests/bug70153.phpt | 2 ++ ext/date/tests/bug71700.phpt | 2 ++ ext/date/tests/bug73091.phpt | 2 ++ ext/date/tests/bug74274.phpt | 1 + ext/date/tests/bug74524.phpt | 1 + ext/date/tests/bug77571.phpt | 3 ++- ext/date/tests/bug78452.phpt | 2 ++ ext/date/tests/bug79015.phpt | 2 ++ ext/date/tests/date_diff1.phpt | 2 ++ ext/date/tests/date_time_fractions.phpt | 2 ++ 26 files changed, 71 insertions(+), 5 deletions(-) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 7dc885d56aae2..0dff004b676c1 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -2093,8 +2093,9 @@ static void date_interval_object_to_hash(php_interval_obj *intervalobj, HashTabl PHP_DATE_INTERVAL_ADD_PROPERTY("special_type", special.type); PHP_DATE_INTERVAL_ADD_PROPERTY("special_amount", special.amount); PHP_DATE_INTERVAL_ADD_PROPERTY("have_weekday_relative", have_weekday_relative); - PHP_DATE_INTERVAL_ADD_PROPERTY("have_special_relative", have_special_relative); } + /* Records whether this is a special relative interval that can't be serialized */ + PHP_DATE_INTERVAL_ADD_PROPERTY("have_special_relative", have_special_relative); #undef PHP_DATE_INTERVAL_ADD_PROPERTY } @@ -4222,6 +4223,10 @@ PHP_METHOD(DateInterval, __serialize) intervalobj = Z_PHPINTERVAL_P(object); DATE_CHECK_INITIALIZED(intervalobj->initialized, DateInterval); + if (intervalobj->diff->have_special_relative) { + zend_throw_exception_ex(NULL, 0, "Serializing special relative time specifications is not supported"); + } + array_init(return_value); myht = Z_ARRVAL_P(return_value); date_interval_object_to_hash(intervalobj, myht, true); diff --git a/ext/date/tests/DatePeriod_set_state.phpt b/ext/date/tests/DatePeriod_set_state.phpt index eaf7d4dfe9e93..558afe3bea56b 100644 --- a/ext/date/tests/DatePeriod_set_state.phpt +++ b/ext/date/tests/DatePeriod_set_state.phpt @@ -53,6 +53,8 @@ object(DatePeriod)#%d (6) { int(0) ["days"]=> bool(false) + ["have_special_relative"]=> + int(0) } ["recurrences"]=> int(25) diff --git a/ext/date/tests/bug45682.phpt b/ext/date/tests/bug45682.phpt index 7568fd07d9bca..989c9451614fd 100644 --- a/ext/date/tests/bug45682.phpt +++ b/ext/date/tests/bug45682.phpt @@ -32,4 +32,6 @@ object(DateInterval)#%d (%d) { int(0) ["days"]=> int(3) + ["have_special_relative"]=> + int(0) } diff --git a/ext/date/tests/bug48678.phpt b/ext/date/tests/bug48678.phpt index df1571a829648..8ef58ca6af7e2 100644 --- a/ext/date/tests/bug48678.phpt +++ b/ext/date/tests/bug48678.phpt @@ -19,6 +19,7 @@ DateInterval Object [f] => 0 [invert] => 0 [days] => + [have_special_relative] => 0 ) DateInterval Object ( @@ -31,4 +32,5 @@ DateInterval Object [f] => 0 [invert] => 0 [days] => + [have_special_relative] => 0 ) diff --git a/ext/date/tests/bug49081.phpt b/ext/date/tests/bug49081.phpt index c29075e17cea9..0e679da8b3a0f 100644 --- a/ext/date/tests/bug49081.phpt +++ b/ext/date/tests/bug49081.phpt @@ -20,4 +20,5 @@ DateInterval Object [f] => 0 [invert] => 0 [days] => 30 + [have_special_relative] => 0 ) diff --git a/ext/date/tests/bug49778.phpt b/ext/date/tests/bug49778.phpt index cce69f8e7748f..2774d1b0a7247 100644 --- a/ext/date/tests/bug49778.phpt +++ b/ext/date/tests/bug49778.phpt @@ -27,6 +27,8 @@ object(DateInterval)#%d (%d) { int(0) ["days"]=> bool(false) + ["have_special_relative"]=> + int(0) } 7 (unknown) diff --git a/ext/date/tests/bug52113.phpt b/ext/date/tests/bug52113.phpt index c6e280cd40668..f973f210162a5 100644 --- a/ext/date/tests/bug52113.phpt +++ b/ext/date/tests/bug52113.phpt @@ -52,6 +52,8 @@ object(DateInterval)#%d (%d) { int(0) ["days"]=> int(0) + ["have_special_relative"]=> + int(0) } string(332) "O:12:"DateInterval":16:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:0;s:1:"h";i:4;s:1:"i";i:0;s:1:"s";i:0;s:1:"f";d:0;s:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:6:"invert";i:0;s:4:"days";i:0;s:12:"special_type";i:0;s:14:"special_amount";i:0;s:21:"have_weekday_relative";i:0;s:21:"have_special_relative";i:0;}" \DateInterval::__set_state(array( @@ -64,6 +66,7 @@ string(332) "O:12:"DateInterval":16:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:0;s:1:"h" 'f' => 0.0, 'invert' => 0, 'days' => 0, + 'have_special_relative' => 0, ))object(DateInterval)#%d (%d) { ["y"]=> int(0) @@ -83,6 +86,8 @@ string(332) "O:12:"DateInterval":16:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:0;s:1:"h" int(0) ["days"]=> int(0) + ["have_special_relative"]=> + int(0) } object(DatePeriod)#%d (6) { ["start"]=> @@ -118,6 +123,8 @@ object(DatePeriod)#%d (6) { int(0) ["days"]=> int(0) + ["have_special_relative"]=> + int(0) } ["recurrences"]=> int(3) @@ -143,6 +150,8 @@ object(DateInterval)#%d (%d) { int(1) ["days"]=> int(2400) + ["have_special_relative"]=> + int(0) } object(DatePeriod)#%d (6) { ["start"]=> @@ -178,6 +187,8 @@ object(DatePeriod)#%d (6) { int(0) ["days"]=> int(0) + ["have_special_relative"]=> + int(0) } ["recurrences"]=> int(3) diff --git a/ext/date/tests/bug52738.phpt b/ext/date/tests/bug52738.phpt index 46be78af1943c..e4d2595e75e22 100644 --- a/ext/date/tests/bug52738.phpt +++ b/ext/date/tests/bug52738.phpt @@ -31,4 +31,5 @@ di Object [f] => 0 [invert] => 0 [days] => + [have_special_relative] => 0 ) diff --git a/ext/date/tests/bug52808.phpt b/ext/date/tests/bug52808.phpt index 190d5184393df..3abd5261bd0bb 100644 --- a/ext/date/tests/bug52808.phpt +++ b/ext/date/tests/bug52808.phpt @@ -44,6 +44,8 @@ object(DateInterval)#%d (%d) { int(1) ["days"]=> int(437) + ["have_special_relative"]=> + int(0) } object(DateInterval)#%d (%d) { ["y"]=> @@ -64,6 +66,8 @@ object(DateInterval)#%d (%d) { int(0) ["days"]=> int(294) + ["have_special_relative"]=> + int(0) } object(DateInterval)#%d (%d) { ["y"]=> @@ -84,6 +88,8 @@ object(DateInterval)#%d (%d) { int(0) ["days"]=> int(294) + ["have_special_relative"]=> + int(0) } Failed to parse interval (2007-05-11T15:30:00Z/) Failed to parse interval (2007-05-11T15:30:00Z) diff --git a/ext/date/tests/bug53437.phpt b/ext/date/tests/bug53437.phpt index 349fd5b39f0b8..afb67ad41a1b8 100644 --- a/ext/date/tests/bug53437.phpt +++ b/ext/date/tests/bug53437.phpt @@ -69,6 +69,8 @@ object(DatePeriod)#%d (6) { int(0) ["days"]=> bool(false) + ["have_special_relative"]=> + int(0) } ["recurrences"]=> int(3) @@ -116,6 +118,8 @@ object(DatePeriod)#%d (6) { int(0) ["days"]=> bool(false) + ["have_special_relative"]=> + int(0) } ["recurrences"]=> int(3) diff --git a/ext/date/tests/bug53437_var2.phpt b/ext/date/tests/bug53437_var2.phpt index 23527684f39ef..b625d572f7a0a 100644 --- a/ext/date/tests/bug53437_var2.phpt +++ b/ext/date/tests/bug53437_var2.phpt @@ -1,5 +1,5 @@ --TEST-- -Bug #53437 DateInterval basic serialization +Bug #53437 (DateInterval basic serialization) --FILE-- bool(false) + ["have_special_relative"]=> + int(0) } object(DateInterval)#2 (%d) { ["y"]=> @@ -51,4 +53,6 @@ object(DateInterval)#2 (%d) { int(0) ["days"]=> bool(false) + ["have_special_relative"]=> + int(0) } diff --git a/ext/date/tests/bug53437_var4.phpt b/ext/date/tests/bug53437_var4.phpt index 05defd24125e4..7c558a24c884f 100644 --- a/ext/date/tests/bug53437_var4.phpt +++ b/ext/date/tests/bug53437_var4.phpt @@ -40,6 +40,8 @@ object(DateInterval)#%d (%d) { int(0) ["days"]=> int(2) + ["have_special_relative"]=> + int(0) } int(0) int(0) diff --git a/ext/date/tests/bug53437_var5.phpt b/ext/date/tests/bug53437_var5.phpt index 61ebffe5237dd..8e04fea933d51 100644 --- a/ext/date/tests/bug53437_var5.phpt +++ b/ext/date/tests/bug53437_var5.phpt @@ -1,5 +1,5 @@ --TEST-- -Bug #53437 DateInterval unserialize bad data, 64 bit +Bug #53437 (DateInterval unserialize bad data, 64 bit) --SKIPIF-- --FILE-- @@ -30,4 +30,6 @@ object(DateInterval)#%d (%d) { int(0) ["days"]=> int(0) + ["have_special_relative"]=> + int(0) } diff --git a/ext/date/tests/bug53437_var6.phpt b/ext/date/tests/bug53437_var6.phpt index e03a28ec6b4c9..aa7657eec14b2 100644 --- a/ext/date/tests/bug53437_var6.phpt +++ b/ext/date/tests/bug53437_var6.phpt @@ -1,5 +1,5 @@ --TEST-- -Bug #53437 DateInterval unserialize bad data, 64 bit +Bug #53437 (DateInterval unserialize bad data, 64 bit) --SKIPIF-- --FILE-- @@ -30,4 +30,6 @@ object(DateInterval)#%d (%d) { int(0) ["days"]=> int(0) + ["have_special_relative"]=> + int(0) } diff --git a/ext/date/tests/bug60774.phpt b/ext/date/tests/bug60774.phpt index 6349ee0f37348..130048e71de4c 100644 --- a/ext/date/tests/bug60774.phpt +++ b/ext/date/tests/bug60774.phpt @@ -27,6 +27,8 @@ object(DateInterval)#1 (%d) { int(0) ["days"]=> bool(false) + ["have_special_relative"]=> + int(0) } 2 (unknown) diff --git a/ext/date/tests/bug66545.phpt b/ext/date/tests/bug66545.phpt index 85518920f433a..efe3e6d1eab44 100644 --- a/ext/date/tests/bug66545.phpt +++ b/ext/date/tests/bug66545.phpt @@ -27,4 +27,5 @@ DateInterval Object [f] => 0 [invert] => 0 [days] => 14 + [have_special_relative] => 0 ) diff --git a/ext/date/tests/bug70153.phpt b/ext/date/tests/bug70153.phpt index ca82dba980cc9..556a5b4f7fd8d 100644 --- a/ext/date/tests/bug70153.phpt +++ b/ext/date/tests/bug70153.phpt @@ -25,6 +25,7 @@ DateInterval Object [f] => 0 [invert] => 0 [days] => + [have_special_relative] => 0 ) O:12:"DateInterval":16:{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:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:6:"invert";i:0;s:4:"days";b:0;s:12:"special_type";i:0;s:14:"special_amount";i:0;s:21:"have_weekday_relative";i:0;s:21:"have_special_relative";i:0;}DateInterval Object ( @@ -37,6 +38,7 @@ O:12:"DateInterval":16:{s:1:"y";i:0;s:1:"m";i:1;s:1:"d";i:0;s:1:"h";i:0;s:1:"i"; [f] => 0 [invert] => 0 [days] => + [have_special_relative] => 0 ) bool(false) bool(false) diff --git a/ext/date/tests/bug71700.phpt b/ext/date/tests/bug71700.phpt index 8a9ec3992fc02..243511fbf976a 100644 --- a/ext/date/tests/bug71700.phpt +++ b/ext/date/tests/bug71700.phpt @@ -31,4 +31,6 @@ object(DateInterval)#3 (%d) { int(0) ["days"]=> int(30) + ["have_special_relative"]=> + int(0) } diff --git a/ext/date/tests/bug73091.phpt b/ext/date/tests/bug73091.phpt index b75951d036e4c..7f16a024ad5b6 100644 --- a/ext/date/tests/bug73091.phpt +++ b/ext/date/tests/bug73091.phpt @@ -31,4 +31,6 @@ object(DateInterval)#%d (%d) { int(0) ["days"]=> int(-1) + ["have_special_relative"]=> + int(0) } diff --git a/ext/date/tests/bug74274.phpt b/ext/date/tests/bug74274.phpt index f5b7f6595454c..b83a2b641c898 100644 --- a/ext/date/tests/bug74274.phpt +++ b/ext/date/tests/bug74274.phpt @@ -20,4 +20,5 @@ DateInterval Object [f] => 0 [invert] => 0 [days] => 1 + [have_special_relative] => 0 ) diff --git a/ext/date/tests/bug74524.phpt b/ext/date/tests/bug74524.phpt index 40cca02108858..93f4cd9209928 100644 --- a/ext/date/tests/bug74524.phpt +++ b/ext/date/tests/bug74524.phpt @@ -22,4 +22,5 @@ DateInterval Object [f] => 0.920541 [invert] => 1 [days] => 227 + [have_special_relative] => 0 ) diff --git a/ext/date/tests/bug77571.phpt b/ext/date/tests/bug77571.phpt index 673b943256e47..bc85354002cba 100644 --- a/ext/date/tests/bug77571.phpt +++ b/ext/date/tests/bug77571.phpt @@ -1,5 +1,5 @@ --TEST-- -Bug #77571 (DateTime's diff DateInterval incorrect in timezones from UTC+01:00 to UTC+12:00 +Bug #77571 (DateTime's diff DateInterval incorrect in timezones from UTC+01:00 to UTC+12:00) --FILE-- 0 [invert] => 0 [days] => 35 + [have_special_relative] => 0 ) diff --git a/ext/date/tests/bug78452.phpt b/ext/date/tests/bug78452.phpt index dec40fafea306..ac4aa887f2862 100644 --- a/ext/date/tests/bug78452.phpt +++ b/ext/date/tests/bug78452.phpt @@ -27,4 +27,6 @@ object(DateInterval)#3 (%d) { int(1) ["days"]=> int(33) + ["have_special_relative"]=> + int(0) } diff --git a/ext/date/tests/bug79015.phpt b/ext/date/tests/bug79015.phpt index 2059658e1e05c..69a197563ea83 100644 --- a/ext/date/tests/bug79015.phpt +++ b/ext/date/tests/bug79015.phpt @@ -25,4 +25,6 @@ object(DateInterval)#%d (%d) { int(0) ["days"]=> bool(false) + ["have_special_relative"]=> + int(0) } diff --git a/ext/date/tests/date_diff1.phpt b/ext/date/tests/date_diff1.phpt index e3556590f8e3e..437e43fc640ad 100644 --- a/ext/date/tests/date_diff1.phpt +++ b/ext/date/tests/date_diff1.phpt @@ -47,4 +47,6 @@ object(DateInterval)#%d (%d) { int(0) ["days"]=> int(33) + ["have_special_relative"]=> + int(0) } diff --git a/ext/date/tests/date_time_fractions.phpt b/ext/date/tests/date_time_fractions.phpt index 215b7c92333b2..ada2e3e772074 100644 --- a/ext/date/tests/date_time_fractions.phpt +++ b/ext/date/tests/date_time_fractions.phpt @@ -77,6 +77,8 @@ object(DateInterval)#%d (%d) { int(0) ["days"]=> int(0) + ["have_special_relative"]=> + int(0) } 2016-10-03 13:20:06.724934 2016-10-03 13:20:07.103123 From c280121b72c31b9fec724bcbf39456adb94ab93e Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Fri, 15 Apr 2022 10:55:59 +0100 Subject: [PATCH 05/13] Add a few test cases for DateInterval --- .../tests/DateInterval_serialize-001.phpt | 111 +++++++++++++ .../tests/DateInterval_serialize-002.phpt | 155 ++++++++++++++++++ .../tests/DateInterval_serialize-003.phpt | 45 +++++ 3 files changed, 311 insertions(+) create mode 100644 ext/date/tests/DateInterval_serialize-001.phpt create mode 100644 ext/date/tests/DateInterval_serialize-002.phpt create mode 100644 ext/date/tests/DateInterval_serialize-003.phpt diff --git a/ext/date/tests/DateInterval_serialize-001.phpt b/ext/date/tests/DateInterval_serialize-001.phpt new file mode 100644 index 0000000000000..f0834172fb73e --- /dev/null +++ b/ext/date/tests/DateInterval_serialize-001.phpt @@ -0,0 +1,111 @@ +--TEST-- +Test DateInterval::__serialize and DateInterval::__unserialize +--FILE-- +__serialize()); +?> +--EXPECTF-- +Original object: +object(DateInterval)#1 (10) { + ["y"]=> + int(2) + ["m"]=> + int(0) + ["d"]=> + int(4) + ["h"]=> + int(6) + ["i"]=> + int(8) + ["s"]=> + int(0) + ["f"]=> + float(0) + ["invert"]=> + int(0) + ["days"]=> + bool(false) + ["have_special_relative"]=> + int(0) +} + + +Serialised object: +string(332) "O:12:"DateInterval":16:{s:1:"y";i:2;s:1:"m";i:0;s:1:"d";i:4;s:1:"h";i:6;s:1:"i";i:8;s:1:"s";i:0;s:1:"f";d:0;s:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:6:"invert";i:0;s:4:"days";b:0;s:12:"special_type";i:0;s:14:"special_amount";i:0;s:21:"have_weekday_relative";i:0;s:21:"have_special_relative";i:0;}" + + +Unserialised object: +object(DateInterval)#2 (10) { + ["y"]=> + int(2) + ["m"]=> + int(0) + ["d"]=> + int(4) + ["h"]=> + int(6) + ["i"]=> + int(8) + ["s"]=> + int(0) + ["f"]=> + float(0) + ["invert"]=> + int(0) + ["days"]=> + bool(false) + ["have_special_relative"]=> + int(0) +} + + +Calling __serialize manually: +array(16) { + ["y"]=> + int(2) + ["m"]=> + int(0) + ["d"]=> + int(4) + ["h"]=> + int(6) + ["i"]=> + int(8) + ["s"]=> + int(0) + ["f"]=> + float(0) + ["weekday"]=> + int(0) + ["weekday_behavior"]=> + int(0) + ["first_last_day_of"]=> + int(0) + ["invert"]=> + int(0) + ["days"]=> + bool(false) + ["special_type"]=> + int(0) + ["special_amount"]=> + int(0) + ["have_weekday_relative"]=> + int(0) + ["have_special_relative"]=> + int(0) +} diff --git a/ext/date/tests/DateInterval_serialize-002.phpt b/ext/date/tests/DateInterval_serialize-002.phpt new file mode 100644 index 0000000000000..df31cf1910e18 --- /dev/null +++ b/ext/date/tests/DateInterval_serialize-002.phpt @@ -0,0 +1,155 @@ +--TEST-- +Test DateInterval::__serialize and DateInterval::__unserialize +--FILE-- +diff($d2); +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\nCalling __unserialize manually:\n"; +$d = new DateInterval('P2Y4DT6H8M'); +$d->__unserialize( + [ + 'y' => 43, + 'm' => 3, + 'd' => 24, + 'h' => 1, + 'i' => 12, + 's' => 27, + 'f' => 0.654321, + 'days' => 15820, + ] +); +var_dump($d); +?> +--EXPECTF-- +Original object: +object(DateInterval)#3 (10) { + ["y"]=> + int(43) + ["m"]=> + int(3) + ["d"]=> + int(24) + ["h"]=> + int(1) + ["i"]=> + int(12) + ["s"]=> + int(27) + ["f"]=> + float(0) + ["invert"]=> + int(0) + ["days"]=> + int(15820) + ["have_special_relative"]=> + int(0) +} + + +Serialised object: +string(340) "O:12:"DateInterval":16:{s:1:"y";i:43;s:1:"m";i:3;s:1:"d";i:24;s:1:"h";i:1;s:1:"i";i:12;s:1:"s";i:27;s:1:"f";d:0;s:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:6:"invert";i:0;s:4:"days";i:15820;s:12:"special_type";i:0;s:14:"special_amount";i:0;s:21:"have_weekday_relative";i:0;s:21:"have_special_relative";i:0;}" + + +Unserialised object: +object(DateInterval)#4 (10) { + ["y"]=> + int(43) + ["m"]=> + int(3) + ["d"]=> + int(24) + ["h"]=> + int(1) + ["i"]=> + int(12) + ["s"]=> + int(27) + ["f"]=> + float(0) + ["invert"]=> + int(0) + ["days"]=> + int(15820) + ["have_special_relative"]=> + int(0) +} + + +Calling __serialize manually: +array(16) { + ["y"]=> + int(43) + ["m"]=> + int(3) + ["d"]=> + int(24) + ["h"]=> + int(1) + ["i"]=> + int(12) + ["s"]=> + int(27) + ["f"]=> + float(0) + ["weekday"]=> + int(0) + ["weekday_behavior"]=> + int(0) + ["first_last_day_of"]=> + int(0) + ["invert"]=> + int(0) + ["days"]=> + int(15820) + ["special_type"]=> + int(0) + ["special_amount"]=> + int(0) + ["have_weekday_relative"]=> + int(0) + ["have_special_relative"]=> + int(0) +} + + +Calling __unserialize manually: +object(DateInterval)#5 (10) { + ["y"]=> + int(43) + ["m"]=> + int(3) + ["d"]=> + int(24) + ["h"]=> + int(1) + ["i"]=> + int(12) + ["s"]=> + int(27) + ["f"]=> + float(0.654321) + ["invert"]=> + int(0) + ["days"]=> + int(15820) + ["have_special_relative"]=> + int(0) +} diff --git a/ext/date/tests/DateInterval_serialize-003.phpt b/ext/date/tests/DateInterval_serialize-003.phpt new file mode 100644 index 0000000000000..f32f9d9858d81 --- /dev/null +++ b/ext/date/tests/DateInterval_serialize-003.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test DateInterval::__serialize and DateInterval::__unserialize +--FILE-- +getMessage(), "\n"; +} +?> +--EXPECTF-- +Original object: +object(DateInterval)#1 (10) { + ["y"]=> + int(0) + ["m"]=> + int(0) + ["d"]=> + int(0) + ["h"]=> + int(0) + ["i"]=> + int(0) + ["s"]=> + int(0) + ["f"]=> + float(0) + ["invert"]=> + int(0) + ["days"]=> + bool(false) + ["have_special_relative"]=> + int(1) +} + + +Serialised object: +Serializing special relative time specifications is not supported From c8a6a8abc0447d6d4639f2b9ffd998e471a2d83e Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Fri, 22 Apr 2022 15:29:15 +0100 Subject: [PATCH 06/13] Rename have_special_relative to from_string, fix serialisation constraint, and reorder fields --- ext/date/php_date.c | 20 +++++++------ ext/date/php_date.h | 1 + .../tests/DateInterval_serialize-001.phpt | 24 +++++++++------- .../tests/DateInterval_serialize-002.phpt | 28 +++++++++++-------- .../tests/DateInterval_serialize-003.phpt | 4 +-- ext/date/tests/DatePeriod_set_state.phpt | 4 +-- ext/date/tests/bug45682.phpt | 4 +-- ext/date/tests/bug48678.phpt | 4 +-- ext/date/tests/bug49081.phpt | 2 +- ext/date/tests/bug49778.phpt | 4 +-- ext/date/tests/bug52113.phpt | 26 ++++++++--------- ext/date/tests/bug52738.phpt | 2 +- ext/date/tests/bug52808.phpt | 12 ++++---- ext/date/tests/bug53437.phpt | 8 +++--- ext/date/tests/bug53437_var2.phpt | 8 +++--- ext/date/tests/bug53437_var4.phpt | 4 +-- ext/date/tests/bug53437_var5.phpt | 4 +-- ext/date/tests/bug53437_var6.phpt | 4 +-- ext/date/tests/bug60774.phpt | 4 +-- ext/date/tests/bug66545.phpt | 2 +- ext/date/tests/bug70153.phpt | 6 ++-- ext/date/tests/bug71700.phpt | 4 +-- ext/date/tests/bug73091.phpt | 4 +-- ext/date/tests/bug74274.phpt | 2 +- ext/date/tests/bug74524.phpt | 2 +- ext/date/tests/bug77571.phpt | 2 +- ext/date/tests/bug78452.phpt | 4 +-- ext/date/tests/bug79015.phpt | 4 +-- ext/date/tests/date_diff1.phpt | 4 +-- ext/date/tests/date_time_fractions.phpt | 4 +-- 30 files changed, 108 insertions(+), 97 deletions(-) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 0dff004b676c1..1e1aa03fc6f25 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -2077,11 +2077,6 @@ static void date_interval_object_to_hash(php_interval_obj *intervalobj, HashTabl PHP_DATE_INTERVAL_ADD_PROPERTY("s", s); ZVAL_DOUBLE(&zv, (double)intervalobj->diff->us / 1000000.0); zend_hash_str_update(props, "f", sizeof("f") - 1, &zv); - if (include_fakes) { - PHP_DATE_INTERVAL_ADD_PROPERTY("weekday", weekday); - PHP_DATE_INTERVAL_ADD_PROPERTY("weekday_behavior", weekday_behavior); - PHP_DATE_INTERVAL_ADD_PROPERTY("first_last_day_of", first_last_day_of); - } PHP_DATE_INTERVAL_ADD_PROPERTY("invert", invert); if (intervalobj->diff->days != -99999) { PHP_DATE_INTERVAL_ADD_PROPERTY("days", days); @@ -2090,12 +2085,19 @@ static void date_interval_object_to_hash(php_interval_obj *intervalobj, HashTabl zend_hash_str_update(props, "days", sizeof("days")-1, &zv); } if (include_fakes) { + PHP_DATE_INTERVAL_ADD_PROPERTY("weekday", weekday); + PHP_DATE_INTERVAL_ADD_PROPERTY("weekday_behavior", weekday_behavior); + PHP_DATE_INTERVAL_ADD_PROPERTY("first_last_day_of", first_last_day_of); PHP_DATE_INTERVAL_ADD_PROPERTY("special_type", special.type); PHP_DATE_INTERVAL_ADD_PROPERTY("special_amount", special.amount); PHP_DATE_INTERVAL_ADD_PROPERTY("have_weekday_relative", have_weekday_relative); + PHP_DATE_INTERVAL_ADD_PROPERTY("have_special_relative", have_special_relative); + ZVAL_LONG(&zv, (zend_long)intervalobj->civil_or_wall); + zend_hash_str_update(props, "civil_or_wall", strlen("civil_or_wall"), &zv); } - /* Records whether this is a special relative interval that can't be serialized */ - PHP_DATE_INTERVAL_ADD_PROPERTY("have_special_relative", have_special_relative); + /* Records whether this is a special relative interval that needs to be recreated from a string */ + ZVAL_BOOL(&zv, (zend_bool)intervalobj->from_string); + zend_hash_str_update(props, "from_string", strlen("from_string"), &zv); #undef PHP_DATE_INTERVAL_ADD_PROPERTY } @@ -3095,7 +3097,7 @@ static void php_date_sub(zval *object, zval *interval, zval *return_value) /* {{ intobj = Z_PHPINTERVAL_P(interval); DATE_CHECK_INITIALIZED(intobj->initialized, DateInterval); - if (intobj->diff->have_special_relative) { + if (intobj->diff->have_weekday_relative || intobj->diff->have_special_relative) { php_error_docref(NULL, E_WARNING, "Only non-special relative time specifications are supported for subtraction"); return; } @@ -4223,7 +4225,7 @@ PHP_METHOD(DateInterval, __serialize) intervalobj = Z_PHPINTERVAL_P(object); DATE_CHECK_INITIALIZED(intervalobj->initialized, DateInterval); - if (intervalobj->diff->have_special_relative) { + if (intervalobj->diff->have_weekday_relative || intervalobj->diff->have_special_relative) { zend_throw_exception_ex(NULL, 0, "Serializing special relative time specifications is not supported"); } diff --git a/ext/date/php_date.h b/ext/date/php_date.h index c30d34d3aa76a..9df3c37594887 100644 --- a/ext/date/php_date.h +++ b/ext/date/php_date.h @@ -72,6 +72,7 @@ static inline php_timezone_obj *php_timezone_obj_from_obj(zend_object *obj) { struct _php_interval_obj { timelib_rel_time *diff; int civil_or_wall; + bool from_string; bool initialized; zend_object std; }; diff --git a/ext/date/tests/DateInterval_serialize-001.phpt b/ext/date/tests/DateInterval_serialize-001.phpt index f0834172fb73e..def7fcb2611ca 100644 --- a/ext/date/tests/DateInterval_serialize-001.phpt +++ b/ext/date/tests/DateInterval_serialize-001.phpt @@ -40,13 +40,13 @@ object(DateInterval)#1 (10) { int(0) ["days"]=> bool(false) - ["have_special_relative"]=> - int(0) + ["from_string"]=> + bool(false) } Serialised object: -string(332) "O:12:"DateInterval":16:{s:1:"y";i:2;s:1:"m";i:0;s:1:"d";i:4;s:1:"h";i:6;s:1:"i";i:8;s:1:"s";i:0;s:1:"f";d:0;s:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:6:"invert";i:0;s:4:"days";b:0;s:12:"special_type";i:0;s:14:"special_amount";i:0;s:21:"have_weekday_relative";i:0;s:21:"have_special_relative";i:0;}" +string(380) "O:12:"DateInterval":18:{s:1:"y";i:2;s:1:"m";i:0;s:1:"d";i:4;s:1:"h";i:6;s:1:"i";i:8;s:1:"s";i:0;s:1:"f";d:0;s:6:"invert";i:0;s:4:"days";b:0;s:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:12:"special_type";i:0;s:14:"special_amount";i:0;s:21:"have_weekday_relative";i:0;s:21:"have_special_relative";i:0;s:13:"civil_or_wall";i:2;s:11:"from_string";b:0;}" Unserialised object: @@ -69,13 +69,13 @@ object(DateInterval)#2 (10) { int(0) ["days"]=> bool(false) - ["have_special_relative"]=> - int(0) + ["from_string"]=> + bool(false) } Calling __serialize manually: -array(16) { +array(%d) { ["y"]=> int(2) ["m"]=> @@ -90,16 +90,16 @@ array(16) { int(0) ["f"]=> float(0) + ["invert"]=> + int(0) + ["days"]=> + bool(false) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) - ["invert"]=> - int(0) - ["days"]=> - bool(false) ["special_type"]=> int(0) ["special_amount"]=> @@ -108,4 +108,8 @@ array(16) { int(0) ["have_special_relative"]=> int(0) + ["civil_or_wall"]=> + int(2) + ["from_string"]=> + bool(false) } diff --git a/ext/date/tests/DateInterval_serialize-002.phpt b/ext/date/tests/DateInterval_serialize-002.phpt index df31cf1910e18..e72c39edc48a5 100644 --- a/ext/date/tests/DateInterval_serialize-002.phpt +++ b/ext/date/tests/DateInterval_serialize-002.phpt @@ -59,13 +59,13 @@ object(DateInterval)#3 (10) { int(0) ["days"]=> int(15820) - ["have_special_relative"]=> - int(0) + ["from_string"]=> + bool(false) } Serialised object: -string(340) "O:12:"DateInterval":16:{s:1:"y";i:43;s:1:"m";i:3;s:1:"d";i:24;s:1:"h";i:1;s:1:"i";i:12;s:1:"s";i:27;s:1:"f";d:0;s:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:6:"invert";i:0;s:4:"days";i:15820;s:12:"special_type";i:0;s:14:"special_amount";i:0;s:21:"have_weekday_relative";i:0;s:21:"have_special_relative";i:0;}" +string(388) "O:12:"DateInterval":18:{s:1:"y";i:43;s:1:"m";i:3;s:1:"d";i:24;s:1:"h";i:1;s:1:"i";i:12;s:1:"s";i:27;s:1:"f";d:0;s:6:"invert";i:0;s:4:"days";i:15820;s:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:12:"special_type";i:0;s:14:"special_amount";i:0;s:21:"have_weekday_relative";i:0;s:21:"have_special_relative";i:0;s:13:"civil_or_wall";i:1;s:11:"from_string";b:0;}" Unserialised object: @@ -88,13 +88,13 @@ object(DateInterval)#4 (10) { int(0) ["days"]=> int(15820) - ["have_special_relative"]=> - int(0) + ["from_string"]=> + bool(false) } Calling __serialize manually: -array(16) { +array(%d) { ["y"]=> int(43) ["m"]=> @@ -109,16 +109,16 @@ array(16) { int(27) ["f"]=> float(0) + ["invert"]=> + int(0) + ["days"]=> + int(15820) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) - ["invert"]=> - int(0) - ["days"]=> - int(15820) ["special_type"]=> int(0) ["special_amount"]=> @@ -127,6 +127,10 @@ array(16) { int(0) ["have_special_relative"]=> int(0) + ["civil_or_wall"]=> + int(1) + ["from_string"]=> + bool(false) } @@ -150,6 +154,6 @@ object(DateInterval)#5 (10) { int(0) ["days"]=> int(15820) - ["have_special_relative"]=> - int(0) + ["from_string"]=> + bool(false) } diff --git a/ext/date/tests/DateInterval_serialize-003.phpt b/ext/date/tests/DateInterval_serialize-003.phpt index f32f9d9858d81..9b52c39c244ae 100644 --- a/ext/date/tests/DateInterval_serialize-003.phpt +++ b/ext/date/tests/DateInterval_serialize-003.phpt @@ -36,8 +36,8 @@ object(DateInterval)#1 (10) { int(0) ["days"]=> bool(false) - ["have_special_relative"]=> - int(1) + ["from_string"]=> + bool(false) } diff --git a/ext/date/tests/DatePeriod_set_state.phpt b/ext/date/tests/DatePeriod_set_state.phpt index 558afe3bea56b..de41eac50a5f9 100644 --- a/ext/date/tests/DatePeriod_set_state.phpt +++ b/ext/date/tests/DatePeriod_set_state.phpt @@ -53,8 +53,8 @@ object(DatePeriod)#%d (6) { int(0) ["days"]=> bool(false) - ["have_special_relative"]=> - int(0) + ["from_string"]=> + bool(false) } ["recurrences"]=> int(25) diff --git a/ext/date/tests/bug45682.phpt b/ext/date/tests/bug45682.phpt index 989c9451614fd..84178aadb8447 100644 --- a/ext/date/tests/bug45682.phpt +++ b/ext/date/tests/bug45682.phpt @@ -32,6 +32,6 @@ object(DateInterval)#%d (%d) { int(0) ["days"]=> int(3) - ["have_special_relative"]=> - int(0) + ["from_string"]=> + bool(false) } diff --git a/ext/date/tests/bug48678.phpt b/ext/date/tests/bug48678.phpt index 8ef58ca6af7e2..3934b187e7098 100644 --- a/ext/date/tests/bug48678.phpt +++ b/ext/date/tests/bug48678.phpt @@ -19,7 +19,7 @@ DateInterval Object [f] => 0 [invert] => 0 [days] => - [have_special_relative] => 0 + [from_string] => ) DateInterval Object ( @@ -32,5 +32,5 @@ DateInterval Object [f] => 0 [invert] => 0 [days] => - [have_special_relative] => 0 + [from_string] => ) diff --git a/ext/date/tests/bug49081.phpt b/ext/date/tests/bug49081.phpt index 0e679da8b3a0f..6f98041e8f74d 100644 --- a/ext/date/tests/bug49081.phpt +++ b/ext/date/tests/bug49081.phpt @@ -20,5 +20,5 @@ DateInterval Object [f] => 0 [invert] => 0 [days] => 30 - [have_special_relative] => 0 + [from_string] => ) diff --git a/ext/date/tests/bug49778.phpt b/ext/date/tests/bug49778.phpt index 2774d1b0a7247..d4e1a2c0ace03 100644 --- a/ext/date/tests/bug49778.phpt +++ b/ext/date/tests/bug49778.phpt @@ -27,8 +27,8 @@ object(DateInterval)#%d (%d) { int(0) ["days"]=> bool(false) - ["have_special_relative"]=> - int(0) + ["from_string"]=> + bool(false) } 7 (unknown) diff --git a/ext/date/tests/bug52113.phpt b/ext/date/tests/bug52113.phpt index f973f210162a5..131243d91340b 100644 --- a/ext/date/tests/bug52113.phpt +++ b/ext/date/tests/bug52113.phpt @@ -52,11 +52,11 @@ object(DateInterval)#%d (%d) { int(0) ["days"]=> int(0) - ["have_special_relative"]=> - int(0) + ["from_string"]=> + bool(false) } -string(332) "O:12:"DateInterval":16:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:0;s:1:"h";i:4;s:1:"i";i:0;s:1:"s";i:0;s:1:"f";d:0;s:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:6:"invert";i:0;s:4:"days";i:0;s:12:"special_type";i:0;s:14:"special_amount";i:0;s:21:"have_weekday_relative";i:0;s:21:"have_special_relative";i:0;}" -\DateInterval::__set_state(array( +string(380) "O:12:"DateInterval":18:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:0;s:1:"h";i:4;s:1:"i";i:0;s:1:"s";i:0;s:1:"f";d:0;s:6:"invert";i:0;s:4:"days";i:0;s:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:12:"special_type";i:0;s:14:"special_amount";i:0;s:21:"have_weekday_relative";i:0;s:21:"have_special_relative";i:0;s:13:"civil_or_wall";i:1;s:11:"from_string";b:0;}" +DateInterval::__set_state(array( 'y' => 0, 'm' => 0, 'd' => 0, @@ -66,7 +66,7 @@ string(332) "O:12:"DateInterval":16:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:0;s:1:"h" 'f' => 0.0, 'invert' => 0, 'days' => 0, - 'have_special_relative' => 0, + 'from_string' => false, ))object(DateInterval)#%d (%d) { ["y"]=> int(0) @@ -86,8 +86,8 @@ string(332) "O:12:"DateInterval":16:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:0;s:1:"h" int(0) ["days"]=> int(0) - ["have_special_relative"]=> - int(0) + ["from_string"]=> + bool(false) } object(DatePeriod)#%d (6) { ["start"]=> @@ -123,8 +123,8 @@ object(DatePeriod)#%d (6) { int(0) ["days"]=> int(0) - ["have_special_relative"]=> - int(0) + ["from_string"]=> + bool(false) } ["recurrences"]=> int(3) @@ -150,8 +150,8 @@ object(DateInterval)#%d (%d) { int(1) ["days"]=> int(2400) - ["have_special_relative"]=> - int(0) + ["from_string"]=> + bool(false) } object(DatePeriod)#%d (6) { ["start"]=> @@ -187,8 +187,8 @@ object(DatePeriod)#%d (6) { int(0) ["days"]=> int(0) - ["have_special_relative"]=> - int(0) + ["from_string"]=> + bool(false) } ["recurrences"]=> int(3) diff --git a/ext/date/tests/bug52738.phpt b/ext/date/tests/bug52738.phpt index e4d2595e75e22..e0f3a1ef5c84b 100644 --- a/ext/date/tests/bug52738.phpt +++ b/ext/date/tests/bug52738.phpt @@ -31,5 +31,5 @@ di Object [f] => 0 [invert] => 0 [days] => - [have_special_relative] => 0 + [from_string] => ) diff --git a/ext/date/tests/bug52808.phpt b/ext/date/tests/bug52808.phpt index 3abd5261bd0bb..a059624fdd7a0 100644 --- a/ext/date/tests/bug52808.phpt +++ b/ext/date/tests/bug52808.phpt @@ -44,8 +44,8 @@ object(DateInterval)#%d (%d) { int(1) ["days"]=> int(437) - ["have_special_relative"]=> - int(0) + ["from_string"]=> + bool(false) } object(DateInterval)#%d (%d) { ["y"]=> @@ -66,8 +66,8 @@ object(DateInterval)#%d (%d) { int(0) ["days"]=> int(294) - ["have_special_relative"]=> - int(0) + ["from_string"]=> + bool(false) } object(DateInterval)#%d (%d) { ["y"]=> @@ -88,8 +88,8 @@ object(DateInterval)#%d (%d) { int(0) ["days"]=> int(294) - ["have_special_relative"]=> - int(0) + ["from_string"]=> + bool(false) } Failed to parse interval (2007-05-11T15:30:00Z/) Failed to parse interval (2007-05-11T15:30:00Z) diff --git a/ext/date/tests/bug53437.phpt b/ext/date/tests/bug53437.phpt index afb67ad41a1b8..ed885696bec11 100644 --- a/ext/date/tests/bug53437.phpt +++ b/ext/date/tests/bug53437.phpt @@ -69,8 +69,8 @@ object(DatePeriod)#%d (6) { int(0) ["days"]=> bool(false) - ["have_special_relative"]=> - int(0) + ["from_string"]=> + bool(false) } ["recurrences"]=> int(3) @@ -118,8 +118,8 @@ object(DatePeriod)#%d (6) { int(0) ["days"]=> bool(false) - ["have_special_relative"]=> - int(0) + ["from_string"]=> + bool(false) } ["recurrences"]=> int(3) diff --git a/ext/date/tests/bug53437_var2.phpt b/ext/date/tests/bug53437_var2.phpt index b625d572f7a0a..9ca6a0f6b2762 100644 --- a/ext/date/tests/bug53437_var2.phpt +++ b/ext/date/tests/bug53437_var2.phpt @@ -31,8 +31,8 @@ object(DateInterval)#1 (%d) { int(0) ["days"]=> bool(false) - ["have_special_relative"]=> - int(0) + ["from_string"]=> + bool(false) } object(DateInterval)#2 (%d) { ["y"]=> @@ -53,6 +53,6 @@ object(DateInterval)#2 (%d) { int(0) ["days"]=> bool(false) - ["have_special_relative"]=> - int(0) + ["from_string"]=> + bool(false) } diff --git a/ext/date/tests/bug53437_var4.phpt b/ext/date/tests/bug53437_var4.phpt index 7c558a24c884f..14823fb4ba47f 100644 --- a/ext/date/tests/bug53437_var4.phpt +++ b/ext/date/tests/bug53437_var4.phpt @@ -40,8 +40,8 @@ object(DateInterval)#%d (%d) { int(0) ["days"]=> int(2) - ["have_special_relative"]=> - int(0) + ["from_string"]=> + bool(false) } int(0) int(0) diff --git a/ext/date/tests/bug53437_var5.phpt b/ext/date/tests/bug53437_var5.phpt index 8e04fea933d51..eb3722f38bb36 100644 --- a/ext/date/tests/bug53437_var5.phpt +++ b/ext/date/tests/bug53437_var5.phpt @@ -30,6 +30,6 @@ object(DateInterval)#%d (%d) { int(0) ["days"]=> int(0) - ["have_special_relative"]=> - int(0) + ["from_string"]=> + bool(false) } diff --git a/ext/date/tests/bug53437_var6.phpt b/ext/date/tests/bug53437_var6.phpt index aa7657eec14b2..cb76c66d4d9d3 100644 --- a/ext/date/tests/bug53437_var6.phpt +++ b/ext/date/tests/bug53437_var6.phpt @@ -30,6 +30,6 @@ object(DateInterval)#%d (%d) { int(0) ["days"]=> int(0) - ["have_special_relative"]=> - int(0) + ["from_string"]=> + bool(false) } diff --git a/ext/date/tests/bug60774.phpt b/ext/date/tests/bug60774.phpt index 130048e71de4c..bb4f97f9c3f05 100644 --- a/ext/date/tests/bug60774.phpt +++ b/ext/date/tests/bug60774.phpt @@ -27,8 +27,8 @@ object(DateInterval)#1 (%d) { int(0) ["days"]=> bool(false) - ["have_special_relative"]=> - int(0) + ["from_string"]=> + bool(false) } 2 (unknown) diff --git a/ext/date/tests/bug66545.phpt b/ext/date/tests/bug66545.phpt index efe3e6d1eab44..0d2f337570698 100644 --- a/ext/date/tests/bug66545.phpt +++ b/ext/date/tests/bug66545.phpt @@ -27,5 +27,5 @@ DateInterval Object [f] => 0 [invert] => 0 [days] => 14 - [have_special_relative] => 0 + [from_string] => ) diff --git a/ext/date/tests/bug70153.phpt b/ext/date/tests/bug70153.phpt index 556a5b4f7fd8d..25ddc9bcc2a03 100644 --- a/ext/date/tests/bug70153.phpt +++ b/ext/date/tests/bug70153.phpt @@ -25,9 +25,9 @@ DateInterval Object [f] => 0 [invert] => 0 [days] => - [have_special_relative] => 0 + [from_string] => ) -O:12:"DateInterval":16:{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:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:6:"invert";i:0;s:4:"days";b:0;s:12:"special_type";i:0;s:14:"special_amount";i:0;s:21:"have_weekday_relative";i:0;s:21:"have_special_relative";i:0;}DateInterval Object +O:12:"DateInterval":18:{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:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:12:"special_type";i:0;s:14:"special_amount";i:0;s:21:"have_weekday_relative";i:0;s:21:"have_special_relative";i:0;s:13:"civil_or_wall";i:1;s:11:"from_string";b:0;}DateInterval Object ( [y] => 0 [m] => 1 @@ -38,7 +38,7 @@ O:12:"DateInterval":16:{s:1:"y";i:0;s:1:"m";i:1;s:1:"d";i:0;s:1:"h";i:0;s:1:"i"; [f] => 0 [invert] => 0 [days] => - [have_special_relative] => 0 + [from_string] => ) bool(false) bool(false) diff --git a/ext/date/tests/bug71700.phpt b/ext/date/tests/bug71700.phpt index 243511fbf976a..09f6e76058c52 100644 --- a/ext/date/tests/bug71700.phpt +++ b/ext/date/tests/bug71700.phpt @@ -31,6 +31,6 @@ object(DateInterval)#3 (%d) { int(0) ["days"]=> int(30) - ["have_special_relative"]=> - int(0) + ["from_string"]=> + bool(false) } diff --git a/ext/date/tests/bug73091.phpt b/ext/date/tests/bug73091.phpt index 7f16a024ad5b6..440f2bbca60d2 100644 --- a/ext/date/tests/bug73091.phpt +++ b/ext/date/tests/bug73091.phpt @@ -31,6 +31,6 @@ object(DateInterval)#%d (%d) { int(0) ["days"]=> int(-1) - ["have_special_relative"]=> - int(0) + ["from_string"]=> + bool(false) } diff --git a/ext/date/tests/bug74274.phpt b/ext/date/tests/bug74274.phpt index b83a2b641c898..20387419728de 100644 --- a/ext/date/tests/bug74274.phpt +++ b/ext/date/tests/bug74274.phpt @@ -20,5 +20,5 @@ DateInterval Object [f] => 0 [invert] => 0 [days] => 1 - [have_special_relative] => 0 + [from_string] => ) diff --git a/ext/date/tests/bug74524.phpt b/ext/date/tests/bug74524.phpt index 93f4cd9209928..825fb0be8b301 100644 --- a/ext/date/tests/bug74524.phpt +++ b/ext/date/tests/bug74524.phpt @@ -22,5 +22,5 @@ DateInterval Object [f] => 0.920541 [invert] => 1 [days] => 227 - [have_special_relative] => 0 + [from_string] => ) diff --git a/ext/date/tests/bug77571.phpt b/ext/date/tests/bug77571.phpt index bc85354002cba..84790e0cd67b9 100644 --- a/ext/date/tests/bug77571.phpt +++ b/ext/date/tests/bug77571.phpt @@ -23,5 +23,5 @@ DateInterval Object [f] => 0 [invert] => 0 [days] => 35 - [have_special_relative] => 0 + [from_string] => ) diff --git a/ext/date/tests/bug78452.phpt b/ext/date/tests/bug78452.phpt index ac4aa887f2862..ba6936551168b 100644 --- a/ext/date/tests/bug78452.phpt +++ b/ext/date/tests/bug78452.phpt @@ -27,6 +27,6 @@ object(DateInterval)#3 (%d) { int(1) ["days"]=> int(33) - ["have_special_relative"]=> - int(0) + ["from_string"]=> + bool(false) } diff --git a/ext/date/tests/bug79015.phpt b/ext/date/tests/bug79015.phpt index 69a197563ea83..63dac799c5403 100644 --- a/ext/date/tests/bug79015.phpt +++ b/ext/date/tests/bug79015.phpt @@ -25,6 +25,6 @@ object(DateInterval)#%d (%d) { int(0) ["days"]=> bool(false) - ["have_special_relative"]=> - int(0) + ["from_string"]=> + bool(false) } diff --git a/ext/date/tests/date_diff1.phpt b/ext/date/tests/date_diff1.phpt index 437e43fc640ad..fa2c64ddd59d4 100644 --- a/ext/date/tests/date_diff1.phpt +++ b/ext/date/tests/date_diff1.phpt @@ -47,6 +47,6 @@ object(DateInterval)#%d (%d) { int(0) ["days"]=> int(33) - ["have_special_relative"]=> - int(0) + ["from_string"]=> + bool(false) } diff --git a/ext/date/tests/date_time_fractions.phpt b/ext/date/tests/date_time_fractions.phpt index ada2e3e772074..4536e0f2eb21e 100644 --- a/ext/date/tests/date_time_fractions.phpt +++ b/ext/date/tests/date_time_fractions.phpt @@ -77,8 +77,8 @@ object(DateInterval)#%d (%d) { int(0) ["days"]=> int(0) - ["have_special_relative"]=> - int(0) + ["from_string"]=> + bool(false) } 2016-10-03 13:20:06.724934 2016-10-03 13:20:07.103123 From 83a6bcc15736b7d4528cbb53f4aafd0c0f37143d Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Fri, 22 Apr 2022 16:11:36 +0100 Subject: [PATCH 07/13] Fixed cloning DateInterval --- ext/date/php_date.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 1e1aa03fc6f25..8d7745d65a8c9 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -2045,6 +2045,8 @@ static zend_object *date_object_clone_interval(zend_object *this_ptr) /* {{{ */ php_interval_obj *new_obj = php_interval_obj_from_obj(date_object_new_interval(old_obj->std.ce)); zend_objects_clone_members(&new_obj->std, &old_obj->std); + new_obj->civil_or_wall = old_obj->civil_or_wall; + new_obj->from_string = old_obj->from_string; new_obj->initialized = old_obj->initialized; if (old_obj->diff) { new_obj->diff = timelib_rel_time_clone(old_obj->diff); From cae1d4adde91ccad25649d7c2ba97bcb266f1d08 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Fri, 22 Apr 2022 16:13:23 +0100 Subject: [PATCH 08/13] Add support for serialising all DateInterval objects --- ext/date/php_date.c | 66 +++++++++++----- ext/date/php_date.h | 1 + .../tests/DateInterval_serialize-001.phpt | 18 +---- .../tests/DateInterval_serialize-002.phpt | 18 +---- .../tests/DateInterval_serialize-003.phpt | 77 ++++++++++++------- ext/date/tests/bug52113.phpt | 2 +- ext/date/tests/bug60774.phpt | 22 +----- ext/date/tests/bug70153.phpt | 29 ++----- 8 files changed, 113 insertions(+), 120 deletions(-) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 8d7745d65a8c9..483ca4995b868 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -2063,10 +2063,19 @@ static HashTable *date_object_get_gc_interval(zend_object *object, zval **table, return zend_std_get_properties(object); } /* }}} */ -static void date_interval_object_to_hash(php_interval_obj *intervalobj, HashTable *props, bool include_fakes) +static void date_interval_object_to_hash(php_interval_obj *intervalobj, HashTable *props) { zval zv; + /* Records whether this is a special relative interval that needs to be recreated from a string */ + if (intervalobj->from_string) { + ZVAL_BOOL(&zv, (zend_bool)intervalobj->from_string); + zend_hash_str_update(props, "from_string", strlen("from_string"), &zv); + ZVAL_STR(&zv, intervalobj->date_string); + zend_hash_str_update(props, "date_string", strlen("date_string"), &zv); + return; + } + #define PHP_DATE_INTERVAL_ADD_PROPERTY(n,f) \ ZVAL_LONG(&zv, (zend_long)intervalobj->diff->f); \ zend_hash_str_update(props, n, sizeof(n)-1, &zv); @@ -2086,18 +2095,6 @@ static void date_interval_object_to_hash(php_interval_obj *intervalobj, HashTabl ZVAL_FALSE(&zv); zend_hash_str_update(props, "days", sizeof("days")-1, &zv); } - if (include_fakes) { - PHP_DATE_INTERVAL_ADD_PROPERTY("weekday", weekday); - PHP_DATE_INTERVAL_ADD_PROPERTY("weekday_behavior", weekday_behavior); - PHP_DATE_INTERVAL_ADD_PROPERTY("first_last_day_of", first_last_day_of); - PHP_DATE_INTERVAL_ADD_PROPERTY("special_type", special.type); - PHP_DATE_INTERVAL_ADD_PROPERTY("special_amount", special.amount); - PHP_DATE_INTERVAL_ADD_PROPERTY("have_weekday_relative", have_weekday_relative); - PHP_DATE_INTERVAL_ADD_PROPERTY("have_special_relative", have_special_relative); - ZVAL_LONG(&zv, (zend_long)intervalobj->civil_or_wall); - zend_hash_str_update(props, "civil_or_wall", strlen("civil_or_wall"), &zv); - } - /* Records whether this is a special relative interval that needs to be recreated from a string */ ZVAL_BOOL(&zv, (zend_bool)intervalobj->from_string); zend_hash_str_update(props, "from_string", strlen("from_string"), &zv); @@ -2115,7 +2112,7 @@ static HashTable *date_object_get_properties_interval(zend_object *object) /* {{ return props; } - date_interval_object_to_hash(intervalobj, props, false); + date_interval_object_to_hash(intervalobj, props); return props; } /* }}} */ @@ -2183,6 +2180,9 @@ static void date_object_free_storage_interval(zend_object *object) /* {{{ */ { php_interval_obj *intern = php_interval_obj_from_obj(object); + if (intern->date_string) { + zend_string_release(intern->date_string); + } timelib_rel_time_dtor(intern->diff); zend_object_std_dtor(&intern->std); } /* }}} */ @@ -4114,6 +4114,35 @@ static void php_date_interval_initialize_from_hash(zval **return_value, php_inte timelib_rel_time_dtor((*intobj)->diff); } + /* If we have a date_string, use that instead */ + zval *date_str = zend_hash_str_find(myht, "date_string", strlen("date_string")); + if (date_str && Z_TYPE_P(date_str) == IS_STRING) { + timelib_time *time; + timelib_error_container *err = NULL; + + time = timelib_strtotime(Z_STRVAL_P(date_str), Z_STRLEN_P(date_str), &err, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper); + + if (err->error_count > 0) { + php_error_docref(NULL, + E_WARNING, + "Unknown or bad format (%s) at position %d (%c) while unserializing: %s", + Z_STRVAL_P(date_str), + err->error_messages[0].position, + err->error_messages[0].character ? err->error_messages[0].character : ' ', err->error_messages[0].message); + } + + (*intobj)->diff = timelib_rel_time_clone(&time->relative); + (*intobj)->initialized = 1; + (*intobj)->civil_or_wall = PHP_DATE_CIVIL; + (*intobj)->from_string = true; + (*intobj)->date_string = zend_string_copy(Z_STR_P(date_str)); + + timelib_time_dtor(time); + timelib_error_container_dtor(err); + + return; + } + /* Set new value */ (*intobj)->diff = timelib_rel_time_ctor(); @@ -4193,6 +4222,7 @@ static void php_date_interval_initialize_from_hash(zval **return_value, php_inte (*intobj)->civil_or_wall = val; } } + (*intobj)->initialized = 1; } /* }}} */ @@ -4227,13 +4257,9 @@ PHP_METHOD(DateInterval, __serialize) intervalobj = Z_PHPINTERVAL_P(object); DATE_CHECK_INITIALIZED(intervalobj->initialized, DateInterval); - if (intervalobj->diff->have_weekday_relative || intervalobj->diff->have_special_relative) { - zend_throw_exception_ex(NULL, 0, "Serializing special relative time specifications is not supported"); - } - array_init(return_value); myht = Z_ARRVAL_P(return_value); - date_interval_object_to_hash(intervalobj, myht, true); + date_interval_object_to_hash(intervalobj, myht); } /* }}} */ @@ -4300,6 +4326,8 @@ PHP_FUNCTION(date_interval_create_from_date_string) diobj->diff = timelib_rel_time_clone(&time->relative); diobj->initialized = 1; diobj->civil_or_wall = PHP_DATE_CIVIL; + diobj->from_string = true; + diobj->date_string = zend_string_copy(time_str); cleanup: timelib_time_dtor(time); diff --git a/ext/date/php_date.h b/ext/date/php_date.h index 9df3c37594887..d18529f10d30f 100644 --- a/ext/date/php_date.h +++ b/ext/date/php_date.h @@ -73,6 +73,7 @@ struct _php_interval_obj { timelib_rel_time *diff; int civil_or_wall; bool from_string; + zend_string *date_string; bool initialized; zend_object std; }; diff --git a/ext/date/tests/DateInterval_serialize-001.phpt b/ext/date/tests/DateInterval_serialize-001.phpt index def7fcb2611ca..276b9e76fbc09 100644 --- a/ext/date/tests/DateInterval_serialize-001.phpt +++ b/ext/date/tests/DateInterval_serialize-001.phpt @@ -46,7 +46,7 @@ object(DateInterval)#1 (10) { Serialised object: -string(380) "O:12:"DateInterval":18:{s:1:"y";i:2;s:1:"m";i:0;s:1:"d";i:4;s:1:"h";i:6;s:1:"i";i:8;s:1:"s";i:0;s:1:"f";d:0;s:6:"invert";i:0;s:4:"days";b:0;s:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:12:"special_type";i:0;s:14:"special_amount";i:0;s:21:"have_weekday_relative";i:0;s:21:"have_special_relative";i:0;s:13:"civil_or_wall";i:2;s:11:"from_string";b:0;}" +string(164) "O:12:"DateInterval":10:{s:1:"y";i:2;s:1:"m";i:0;s:1:"d";i:4;s:1:"h";i:6;s:1:"i";i:8;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;}" Unserialised object: @@ -94,22 +94,6 @@ array(%d) { int(0) ["days"]=> bool(false) - ["weekday"]=> - int(0) - ["weekday_behavior"]=> - int(0) - ["first_last_day_of"]=> - int(0) - ["special_type"]=> - int(0) - ["special_amount"]=> - int(0) - ["have_weekday_relative"]=> - int(0) - ["have_special_relative"]=> - int(0) - ["civil_or_wall"]=> - int(2) ["from_string"]=> bool(false) } diff --git a/ext/date/tests/DateInterval_serialize-002.phpt b/ext/date/tests/DateInterval_serialize-002.phpt index e72c39edc48a5..54daa6062ffc0 100644 --- a/ext/date/tests/DateInterval_serialize-002.phpt +++ b/ext/date/tests/DateInterval_serialize-002.phpt @@ -65,7 +65,7 @@ object(DateInterval)#3 (10) { Serialised object: -string(388) "O:12:"DateInterval":18:{s:1:"y";i:43;s:1:"m";i:3;s:1:"d";i:24;s:1:"h";i:1;s:1:"i";i:12;s:1:"s";i:27;s:1:"f";d:0;s:6:"invert";i:0;s:4:"days";i:15820;s:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:12:"special_type";i:0;s:14:"special_amount";i:0;s:21:"have_weekday_relative";i:0;s:21:"have_special_relative";i:0;s:13:"civil_or_wall";i:1;s:11:"from_string";b:0;}" +string(172) "O:12:"DateInterval":10:{s:1:"y";i:43;s:1:"m";i:3;s:1:"d";i:24;s:1:"h";i:1;s:1:"i";i:12;s:1:"s";i:27;s:1:"f";d:0;s:6:"invert";i:0;s:4:"days";i:15820;s:11:"from_string";b:0;}" Unserialised object: @@ -113,22 +113,6 @@ array(%d) { int(0) ["days"]=> int(15820) - ["weekday"]=> - int(0) - ["weekday_behavior"]=> - int(0) - ["first_last_day_of"]=> - int(0) - ["special_type"]=> - int(0) - ["special_amount"]=> - int(0) - ["have_weekday_relative"]=> - int(0) - ["have_special_relative"]=> - int(0) - ["civil_or_wall"]=> - int(1) ["from_string"]=> bool(false) } diff --git a/ext/date/tests/DateInterval_serialize-003.phpt b/ext/date/tests/DateInterval_serialize-003.phpt index 9b52c39c244ae..04687664a7a80 100644 --- a/ext/date/tests/DateInterval_serialize-003.phpt +++ b/ext/date/tests/DateInterval_serialize-003.phpt @@ -9,37 +9,62 @@ echo "Original object:\n"; var_dump($d); echo "\n\nSerialised object:\n"; -try { - $s = serialize($d); -} catch (Exception $e) { - echo $e->getMessage(), "\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\nCalling __unserialize manually:\n"; +$d = new DateInterval('P2Y4DT6H8M'); +$d->__unserialize( + [ + 'from_string' => true, + 'date_string' => 'next weekday 15:30', + ] +); +var_dump($d); ?> --EXPECTF-- Original object: -object(DateInterval)#1 (10) { - ["y"]=> - int(0) - ["m"]=> - int(0) - ["d"]=> - int(0) - ["h"]=> - int(0) - ["i"]=> - int(0) - ["s"]=> - int(0) - ["f"]=> - float(0) - ["invert"]=> - int(0) - ["days"]=> - bool(false) +object(DateInterval)#1 (%d) { ["from_string"]=> - bool(false) + bool(true) + ["date_string"]=> + string(18) "next weekday 15:30" } Serialised object: -Serializing special relative time specifications is not supported +string(92) "O:12:"DateInterval":2:{s:11:"from_string";b:1;s:11:"date_string";s:18:"next weekday 15:30";}" + + +Unserialised object: +object(DateInterval)#2 (2) { + ["from_string"]=> + bool(true) + ["date_string"]=> + string(18) "next weekday 15:30" +} + + +Calling __serialize manually: +array(2) { + ["from_string"]=> + bool(true) + ["date_string"]=> + string(18) "next weekday 15:30" +} + + +Calling __unserialize manually: +object(DateInterval)#3 (2) { + ["from_string"]=> + bool(true) + ["date_string"]=> + string(18) "next weekday 15:30" +} diff --git a/ext/date/tests/bug52113.phpt b/ext/date/tests/bug52113.phpt index 131243d91340b..1a8d42ec7295e 100644 --- a/ext/date/tests/bug52113.phpt +++ b/ext/date/tests/bug52113.phpt @@ -55,7 +55,7 @@ object(DateInterval)#%d (%d) { ["from_string"]=> bool(false) } -string(380) "O:12:"DateInterval":18:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:0;s:1:"h";i:4;s:1:"i";i:0;s:1:"s";i:0;s:1:"f";d:0;s:6:"invert";i:0;s:4:"days";i:0;s:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:12:"special_type";i:0;s:14:"special_amount";i:0;s:21:"have_weekday_relative";i:0;s:21:"have_special_relative";i:0;s:13:"civil_or_wall";i:1;s:11:"from_string";b:0;}" +string(164) "O:12:"DateInterval":10:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:0;s:1:"h";i:4;s:1:"i";i:0;s:1:"s";i:0;s:1:"f";d:0;s:6:"invert";i:0;s:4:"days";i:0;s:11:"from_string";b:0;}" DateInterval::__set_state(array( 'y' => 0, 'm' => 0, diff --git a/ext/date/tests/bug60774.phpt b/ext/date/tests/bug60774.phpt index bb4f97f9c3f05..2f3de6bafd141 100644 --- a/ext/date/tests/bug60774.phpt +++ b/ext/date/tests/bug60774.phpt @@ -9,26 +9,10 @@ echo $i->format("%a"), "\n"; ?> --EXPECTF-- object(DateInterval)#1 (%d) { - ["y"]=> - int(0) - ["m"]=> - int(0) - ["d"]=> - int(2) - ["h"]=> - int(0) - ["i"]=> - int(0) - ["s"]=> - int(0) - ["f"]=> - float(0) - ["invert"]=> - int(0) - ["days"]=> - bool(false) ["from_string"]=> - bool(false) + bool(true) + ["date_string"]=> + string(6) "2 days" } 2 (unknown) diff --git a/ext/date/tests/bug70153.phpt b/ext/date/tests/bug70153.phpt index 25ddc9bcc2a03..9aaa0e7d538fa 100644 --- a/ext/date/tests/bug70153.phpt +++ b/ext/date/tests/bug70153.phpt @@ -8,6 +8,8 @@ print_r($i1); $s = serialize($i1); print_r($s); +echo "\n"; + $i2 = unserialize($s); print_r($i2); @@ -16,29 +18,14 @@ var_dump($i1->days, $i2->days); --EXPECT-- DateInterval Object ( - [y] => 0 - [m] => 1 - [d] => 0 - [h] => 0 - [i] => 0 - [s] => 0 - [f] => 0 - [invert] => 0 - [days] => - [from_string] => + [from_string] => 1 + [date_string] => +1 month ) -O:12:"DateInterval":18:{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:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:12:"special_type";i:0;s:14:"special_amount";i:0;s:21:"have_weekday_relative";i:0;s:21:"have_special_relative";i:0;s:13:"civil_or_wall";i:1;s:11:"from_string";b:0;}DateInterval Object +O:12:"DateInterval":2:{s:11:"from_string";b:1;s:11:"date_string";s:8:"+1 month";} +DateInterval Object ( - [y] => 0 - [m] => 1 - [d] => 0 - [h] => 0 - [i] => 0 - [s] => 0 - [f] => 0 - [invert] => 0 - [days] => - [from_string] => + [from_string] => 1 + [date_string] => +1 month ) bool(false) bool(false) From 5fb36414a38cd24dc93824c3a2d1d237520260c7 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Fri, 22 Apr 2022 16:12:59 +0100 Subject: [PATCH 09/13] Fixed cloning DateInterval --- ext/date/php_date.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 483ca4995b868..8d2fbdc9e7de4 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -2047,6 +2047,9 @@ static zend_object *date_object_clone_interval(zend_object *this_ptr) /* {{{ */ zend_objects_clone_members(&new_obj->std, &old_obj->std); new_obj->civil_or_wall = old_obj->civil_or_wall; new_obj->from_string = old_obj->from_string; + if (old_obj->date_string) { + new_obj->date_string = zend_string_copy(old_obj->date_string); + } new_obj->initialized = old_obj->initialized; if (old_obj->diff) { new_obj->diff = timelib_rel_time_clone(old_obj->diff); From d57b05249c96f7e34e3bc2ab87d24a31047f9675 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Fri, 29 Apr 2022 09:22:08 +0100 Subject: [PATCH 10/13] Extended tests --- .../tests/DateInterval_serialize-001.phpt | 24 ++++++++++++++++ .../tests/DateInterval_serialize-002.phpt | 24 ++++++++++++++++ .../tests/DateInterval_serialize-003.phpt | 28 +++++++++++++++++++ ext/date/tests/bug52113.phpt | 2 +- 4 files changed, 77 insertions(+), 1 deletion(-) diff --git a/ext/date/tests/DateInterval_serialize-001.phpt b/ext/date/tests/DateInterval_serialize-001.phpt index 276b9e76fbc09..cad33185cf9bb 100644 --- a/ext/date/tests/DateInterval_serialize-001.phpt +++ b/ext/date/tests/DateInterval_serialize-001.phpt @@ -18,6 +18,11 @@ var_dump($e); echo "\n\nCalling __serialize manually:\n"; var_dump($d->__serialize()); + +echo "\n\nUsed serialised interval:\n"; +$now = new DateTimeImmutable("2022-04-22 16:25:11 BST"); +var_dump($now->add($e)); +var_dump($now->sub($e)); ?> --EXPECTF-- Original object: @@ -97,3 +102,22 @@ array(%d) { ["from_string"]=> bool(false) } + + +Used serialised interval: +object(DateTimeImmutable)#4 (3) { + ["date"]=> + string(26) "2024-04-26 22:33:11.000000" + ["timezone_type"]=> + int(2) + ["timezone"]=> + string(3) "BST" +} +object(DateTimeImmutable)#4 (3) { + ["date"]=> + string(26) "2020-04-18 10:17:11.000000" + ["timezone_type"]=> + int(2) + ["timezone"]=> + string(3) "BST" +} diff --git a/ext/date/tests/DateInterval_serialize-002.phpt b/ext/date/tests/DateInterval_serialize-002.phpt index 54daa6062ffc0..d21e02245e695 100644 --- a/ext/date/tests/DateInterval_serialize-002.phpt +++ b/ext/date/tests/DateInterval_serialize-002.phpt @@ -37,6 +37,11 @@ $d->__unserialize( ] ); var_dump($d); + +echo "\n\nUsed serialised interval:\n"; +$now = new DateTimeImmutable("2022-04-15 10:27:27 BST"); +var_dump($now->add($e)); +var_dump($now->sub($e)); ?> --EXPECTF-- Original object: @@ -141,3 +146,22 @@ object(DateInterval)#5 (10) { ["from_string"]=> bool(false) } + + +Used serialised interval: +object(DateTimeImmutable)#6 (3) { + ["date"]=> + string(26) "2065-08-08 11:39:54.000000" + ["timezone_type"]=> + int(2) + ["timezone"]=> + string(3) "BST" +} +object(DateTimeImmutable)#6 (3) { + ["date"]=> + string(26) "1978-12-22 09:15:00.000000" + ["timezone_type"]=> + int(2) + ["timezone"]=> + string(3) "BST" +} diff --git a/ext/date/tests/DateInterval_serialize-003.phpt b/ext/date/tests/DateInterval_serialize-003.phpt index 04687664a7a80..e8915ee515d25 100644 --- a/ext/date/tests/DateInterval_serialize-003.phpt +++ b/ext/date/tests/DateInterval_serialize-003.phpt @@ -4,6 +4,8 @@ Test DateInterval::__serialize and DateInterval::__unserialize __unserialize( ] ); var_dump($d); + +echo "\n\nUsed serialised interval:\n"; +$now = new DateTimeImmutable("2022-04-22 16:25:11 BST"); +var_dump($now->add($e)); +var_dump($now->sub($e)); ?> --EXPECTF-- Original object: @@ -68,3 +75,24 @@ object(DateInterval)#3 (2) { ["date_string"]=> string(18) "next weekday 15:30" } + + +Used serialised interval: +object(DateTimeImmutable)#4 (3) { + ["date"]=> + string(26) "2022-04-25 16:25:11.000000" + ["timezone_type"]=> + int(2) + ["timezone"]=> + string(3) "BST" +} + +Warning: DateTimeImmutable::sub(): Only non-special relative time specifications are supported for subtraction in %s on line %d +object(DateTimeImmutable)#4 (3) { + ["date"]=> + string(26) "2022-04-22 16:25:11.000000" + ["timezone_type"]=> + int(2) + ["timezone"]=> + string(3) "BST" +} diff --git a/ext/date/tests/bug52113.phpt b/ext/date/tests/bug52113.phpt index 1a8d42ec7295e..2e02195bd1d1a 100644 --- a/ext/date/tests/bug52113.phpt +++ b/ext/date/tests/bug52113.phpt @@ -56,7 +56,7 @@ object(DateInterval)#%d (%d) { bool(false) } string(164) "O:12:"DateInterval":10:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:0;s:1:"h";i:4;s:1:"i";i:0;s:1:"s";i:0;s:1:"f";d:0;s:6:"invert";i:0;s:4:"days";i:0;s:11:"from_string";b:0;}" -DateInterval::__set_state(array( +\DateInterval::__set_state(array( 'y' => 0, 'm' => 0, 'd' => 0, From 8a67d7c3630968e2ea94866718ecf5ca7bb61904 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Fri, 29 Apr 2022 11:25:55 +0100 Subject: [PATCH 11/13] Update related test in ext/standard --- ext/standard/tests/serialize/bug69425.phpt | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/ext/standard/tests/serialize/bug69425.phpt b/ext/standard/tests/serialize/bug69425.phpt index 906c7192fb20a..1bc79c0387c8c 100644 --- a/ext/standard/tests/serialize/bug69425.phpt +++ b/ext/standard/tests/serialize/bug69425.phpt @@ -1,5 +1,5 @@ --TEST-- -Bug #69425: Use After Free in unserialize() +Bug #69425 (Use After Free in unserialize()) --FILE-- ---EXPECT-- +--EXPECTF-- int(1) array(2) { [0]=> - object(DateInterval)#1 (16) { + object(DateInterval)#1 (%d) { ["y"]=> int(-1) ["m"]=> @@ -41,24 +41,12 @@ array(2) { int(-1) ["f"]=> float(0) - ["weekday"]=> - int(-1) - ["weekday_behavior"]=> - int(-1) - ["first_last_day_of"]=> - int(-1) ["invert"]=> int(0) ["days"]=> int(-1) - ["special_type"]=> - int(0) - ["special_amount"]=> - int(-1) - ["have_weekday_relative"]=> - int(0) - ["have_special_relative"]=> - int(0) + ["from_string"]=> + bool(false) } [1]=> int(2) From ef30c9ed98eb059b2f79373d2c147896dd24df32 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Fri, 29 Apr 2022 14:19:27 +0100 Subject: [PATCH 12/13] Update 32-bit only test --- ext/date/tests/bug53437_var3.phpt | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/ext/date/tests/bug53437_var3.phpt b/ext/date/tests/bug53437_var3.phpt index eb043398e2daa..6fd5f11f0301b 100644 --- a/ext/date/tests/bug53437_var3.phpt +++ b/ext/date/tests/bug53437_var3.phpt @@ -11,7 +11,7 @@ var_dump($di); ?> --EXPECTF-- -object(DateInterval)#%d (16) { +object(DateInterval)#%d (%d) { ["y"]=> int(2) ["m"]=> @@ -24,24 +24,12 @@ object(DateInterval)#%d (16) { int(8) ["s"]=> int(0) - ["weekday"]=> - int(10) - ["weekday_behavior"]=> - int(10) - ["first_last_day_of"]=> - int(0) + ["f"]=> + float(0) ["invert"]=> int(0) ["days"]=> int(0) - ["special_type"]=> - int(0) - ["special_amount"]=> - int(-1) - ["have_weekday_relative"]=> - int(%d) - ["have_special_relative"]=> - int(0) - ["f"]=> - float(0) + ["from_string"]=> + bool(false) } From c1ad706b8264b59a65777660ba2d82b77247a047 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Fri, 29 Apr 2022 14:33:16 +0100 Subject: [PATCH 13/13] Fixed reference count issue with zend_string --- ext/date/php_date.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 8d2fbdc9e7de4..ed66a4a4b9a70 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -2074,7 +2074,7 @@ static void date_interval_object_to_hash(php_interval_obj *intervalobj, HashTabl if (intervalobj->from_string) { ZVAL_BOOL(&zv, (zend_bool)intervalobj->from_string); zend_hash_str_update(props, "from_string", strlen("from_string"), &zv); - ZVAL_STR(&zv, intervalobj->date_string); + ZVAL_STR_COPY(&zv, intervalobj->date_string); zend_hash_str_update(props, "date_string", strlen("date_string"), &zv); return; } @@ -2185,6 +2185,7 @@ static void date_object_free_storage_interval(zend_object *object) /* {{{ */ if (intern->date_string) { zend_string_release(intern->date_string); + intern->date_string = NULL; } timelib_rel_time_dtor(intern->diff); zend_object_std_dtor(&intern->std);