1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Rename have_special_relative to from_string, fix serialisation constraint, and reorder fields

This commit is contained in:
Derick Rethans
2022-04-22 15:29:15 +01:00
parent c280121b72
commit c8a6a8abc0
30 changed files with 108 additions and 97 deletions

View File

@@ -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");
}

View File

@@ -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;
};

View File

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

View File

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

View File

@@ -36,8 +36,8 @@ object(DateInterval)#1 (10) {
int(0)
["days"]=>
bool(false)
["have_special_relative"]=>
int(1)
["from_string"]=>
bool(false)
}

View File

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

View File

@@ -32,6 +32,6 @@ object(DateInterval)#%d (%d) {
int(0)
["days"]=>
int(3)
["have_special_relative"]=>
int(0)
["from_string"]=>
bool(false)
}

View File

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

View File

@@ -20,5 +20,5 @@ DateInterval Object
[f] => 0
[invert] => 0
[days] => 30
[have_special_relative] => 0
[from_string] =>
)

View File

@@ -27,8 +27,8 @@ object(DateInterval)#%d (%d) {
int(0)
["days"]=>
bool(false)
["have_special_relative"]=>
int(0)
["from_string"]=>
bool(false)
}
7
(unknown)

View File

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

View File

@@ -31,5 +31,5 @@ di Object
[f] => 0
[invert] => 0
[days] =>
[have_special_relative] => 0
[from_string] =>
)

View File

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

View File

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

View File

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

View File

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

View File

@@ -30,6 +30,6 @@ object(DateInterval)#%d (%d) {
int(0)
["days"]=>
int(0)
["have_special_relative"]=>
int(0)
["from_string"]=>
bool(false)
}

View File

@@ -30,6 +30,6 @@ object(DateInterval)#%d (%d) {
int(0)
["days"]=>
int(0)
["have_special_relative"]=>
int(0)
["from_string"]=>
bool(false)
}

View File

@@ -27,8 +27,8 @@ object(DateInterval)#1 (%d) {
int(0)
["days"]=>
bool(false)
["have_special_relative"]=>
int(0)
["from_string"]=>
bool(false)
}
2
(unknown)

View File

@@ -27,5 +27,5 @@ DateInterval Object
[f] => 0
[invert] => 0
[days] => 14
[have_special_relative] => 0
[from_string] =>
)

View File

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

View File

@@ -31,6 +31,6 @@ object(DateInterval)#3 (%d) {
int(0)
["days"]=>
int(30)
["have_special_relative"]=>
int(0)
["from_string"]=>
bool(false)
}

View File

@@ -31,6 +31,6 @@ object(DateInterval)#%d (%d) {
int(0)
["days"]=>
int(-1)
["have_special_relative"]=>
int(0)
["from_string"]=>
bool(false)
}

View File

@@ -20,5 +20,5 @@ DateInterval Object
[f] => 0
[invert] => 0
[days] => 1
[have_special_relative] => 0
[from_string] =>
)

View File

@@ -22,5 +22,5 @@ DateInterval Object
[f] => 0.920541
[invert] => 1
[days] => 227
[have_special_relative] => 0
[from_string] =>
)

View File

@@ -23,5 +23,5 @@ DateInterval Object
[f] => 0
[invert] => 0
[days] => 35
[have_special_relative] => 0
[from_string] =>
)

View File

@@ -27,6 +27,6 @@ object(DateInterval)#3 (%d) {
int(1)
["days"]=>
int(33)
["have_special_relative"]=>
int(0)
["from_string"]=>
bool(false)
}

View File

@@ -25,6 +25,6 @@ object(DateInterval)#%d (%d) {
int(0)
["days"]=>
bool(false)
["have_special_relative"]=>
int(0)
["from_string"]=>
bool(false)
}

View File

@@ -47,6 +47,6 @@ object(DateInterval)#%d (%d) {
int(0)
["days"]=>
int(33)
["have_special_relative"]=>
int(0)
["from_string"]=>
bool(false)
}

View File

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