8000 Remove fake properties from DateInterval · php/php-src@3be8b5f · GitHub
[go: up one dir, main page]

Skip to content

Commit 3be8b5f

Browse files
committed
Remove fake properties from DateInterval
1 parent b46632e commit 3be8b5f

26 files changed

+91
-464
lines changed

ext/date/php_date.c

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,17 +2061,9 @@ static HashTable *date_object_get_gc_interval(zend_object *object, zval **table,
20612061
return zend_std_get_properties(object);
20622062
} /* }}} */
20632063

2064-
static HashTable *date_object_get_properties_interval(zend_object *object) /* {{{ */
2064+
static void date_interval_object_to_hash(php_interval_obj *intervalobj, HashTable *props, bool include_fakes)
20652065
{
2066-
HashTable *props;
20672066
zval zv;
2068-
php_interval_obj *intervalobj;
2069-
2070-
intervalobj = php_interval_obj_from_obj(object);
2071-
props = zend_std_get_properties(object);
2072-
if (!intervalobj->initialized) {
2073-
return props;
2074-
}
20752067

20762068
#define PHP_DATE_INTERVAL_ADD_PROPERTY(n,f) \
20772069
ZVAL_LONG(&zv, (zend_long)intervalobj->diff->f); \
@@ -2085,20 +2077,40 @@ static HashTable *date_object_get_properties_interval(zend_object *object) /* {{
20852077
PHP_DATE_INTERVAL_ADD_PROPERTY("s", s);
20862078
ZVAL_DOUBLE(&zv, (double)intervalobj->diff->us / 1000000.0);
20872079
zend_hash_str_update(props, "f", sizeof("f") - 1, &zv);
2088-
PHP_DATE_INTERVAL_ADD_PROPERTY("weekday", weekday);
2089-
PHP_DATE_INTERVAL_ADD_PROPERTY("weekday_behavior", weekday_behavior);
2090-
PHP_DATE_INTERVAL_ADD_PROPERTY("first_last_day_of", first_last_day_of);
2080+
if (include_fakes) {
2081+
PHP_DATE_INTERVAL_ADD_PROPERTY("weekday", weekday);
2082+
PHP_DATE_INTERVAL_ADD_PROPERTY("weekday_behavior", weekday_behavior);
2083+
PHP_DATE_INTERVAL_ADD_PROPERTY("first_last_day_of", first_last_day_of);
2084+
}
20912085
PHP_DATE_INTERVAL_ADD_PROPERTY("invert", invert);
20922086
if (intervalobj->diff->days != -99999) {
20932087
PHP_DATE_INTERVAL_ADD_PROPERTY("days", days);
20942088
} else {
20952089
ZVAL_FALSE(&zv);
20962090
zend_hash_str_update(props, "days", sizeof("days")-1, &zv);
20972091
}
2098-
PHP_DATE_INTERVAL_ADD_PROPERTY("special_type", special.type);
2099-
PHP_DATE_INTERVAL_ADD_PROPERTY("special_amount", special.amount);
2100-
PHP_DATE_INTERVAL_ADD_PROPERTY("have_weekday_relative", have_weekday_relative);
2101-
PHP_DATE_INTERVAL_ADD_PROPERTY("have_special_relative", have_special_relative);
2092+
if (include_fakes) {
2093+
PHP_DATE_INTERVAL_ADD_PROPERTY("special_type", special.type);
2094+
PHP_DATE_INTERVAL_ADD_PROPERTY("special_amount", special.amount);
2095+
PHP_DATE_INTERVAL_ADD_PROPERTY("have_weekday_relative", have_weekday_relative);
2096+
PHP_DATE_INTERVAL_ADD_PROPERTY("have_special_relative", have_special_relative);
2097+
}
2098+
2099+
#undef PHP_DATE_INTERVAL_ADD_PROPERTY
2100+
}
2101+
2102+
static HashTable *date_object_get_properties_interval(zend_object *object) /* {{{ */
2103+
{
2104+
HashTable *props;
2105+
php_interval_obj *intervalobj;
2106+
2107+
intervalobj = php_interval_obj_from_obj(object);
2108+
props = zend_std_get_properties(object);
2109+
if (!intervalobj->initialized) {
2110+
return props;
2111+
}
2112+
2113+
date_interval_object_to_hash(intervalobj, props, false);
21022114

21032115
return props;
21042116
} /* }}} */

ext/date/tests/DatePeriod_set_state.phpt

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ object(DatePeriod)#%d (6) {
3434
["end"]=>
3535
NULL
3636
["interval"]=>
37-
object(DateInterval)#%d (16) {
37+
object(DateInterval)#%d (%d) {
3838
["y"]=>
3939
int(0)
4040
["m"]=>
@@ -49,24 +49,10 @@ object(DatePeriod)#%d (6) {
4949
int(0)
5050
["f"]=>
5151
float(0)
52-
["weekday"]=>
53-
int(0)
54-
["weekday_behavior"]=>
55-
int(0)
56-
["first_last_day_of"]=>
57-
int(0)
5852
["invert"]=>
5953
int(0)
6054
["days"]=>
6155
bool(false)
62-
["special_type"]=>
63-
int(0)
64-
["special_amount"]=>
65-
int(0)
66-
["have_weekday_relative"]=>
67-
int(0)
68-
["have_special_relative"]=>
69-
int(0)
7056
}
7157
["recurrences"]=>
7258
int(25)

ext/date/tests/bug45682.phpt

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ $diff = date_diff($date, $other);
1313
var_dump($diff);
1414
?>
1515
--EXPECTF--
16-
object(DateInterval)#%d (16) {
16+
object(DateInterval)#%d (%d) {
1717
["y"]=>
1818
int(0)
1919
["m"]=>
@@ -28,22 +28,8 @@ object(DateInterval)#%d (16) {
2828
int(0)
2929
["f"]=>
3030
float(0)
31-
["weekday"]=>
32-
int(0)
33-
["weekday_behavior"]=>
34-
int(0)
35-
["first_last_day_of"]=>
36-
int(0)
3731
["invert"]=>
3832
int(0)
3933
["days"]=>
4034
int(3)
41-
["special_type"]=>
42-
int(0)
43-
["special_amount"]=>
44-
int(0)
45-
["have_weekday_relative"]=>
46-
int(0)
47-
["have_special_relative"]=>
48-
int(0)
4935
}

ext/date/tests/bug48678.phpt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,8 @@ DateInterval Object
1717
[i] => 30
1818
[s] => 5
1919
[f] => 0
20-
[weekday] => 0
21-
[weekday_behavior] => 0
22-
[first_last_day_of] => 0
2320
[invert] => 0
2421
[days] =>
25-
[special_type] => 0
26-
[special_amount] => 0
27-
[have_weekday_relative] => 0
28-
[have_special_relative] => 0
2922
)
3023
DateInterval Object
3124
(
@@ -36,13 +29,6 @@ DateInterval Object
3629
[i] => 30
3730
[s] => 5
3831
[f] => 0
39-
[weekday] => 0
40-
[weekday_behavior] => 0
41-
[first_last_day_of] => 0
4232
[invert] => 0
4333
[days] =>
44-
[special_type] => 0
45-
[special_amount] => 0
46-
[have_weekday_relative] => 0
47-
[have_special_relative] => 0
4834
)

ext/date/tests/bug49081.phpt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@ DateInterval Object
1818
[i] => 0
1919
[s] => 0
2020
[f] => 0
21-
[weekday] => 0
22-
[weekday_behavior] => 0
23-
[first_last_day_of] => 0
2421
[invert] => 0
2522
[days] => 30
26-
[special_type] => 0
27-
[special_amount] => 0
28-
[have_weekday_relative] => 0
29-
[have_special_relative] => 0
3023
)

ext/date/tests/bug49778.phpt

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ echo $i->format("%d"), "\n";
88
echo $i->format("%a"), "\n";
99
?>
1010
--EXPECTF--
11-
object(DateInterval)#%d (16) {
11+
object(DateInterval)#%d (%d) {
1212
["y"]=>
1313
int(0)
1414
["m"]=>
@@ -23,24 +23,10 @@ object(DateInterval)#%d (16) {
2323
int(0)
2424
["f"]=>
2525
float(0)
26-
["weekday"]=>
27-
int(0)
28-
["weekday_behavior"]=>
29-
int(0)
30-
["first_last_day_of"]=>
31-
int(0)
3226
["invert"]=>
3327
int(0)
3428
["days"]=>
3529
bool(false)
36-
["special_type"]=>
37-
int(0)
38-
["special_amount"]=>
39-
int(0)
40-
["have_weekday_relative"]=>
41-
int(0)
42-
["have_special_relative"]=>
43-
int(0)
4430
}
4531
7
4632
(unknown)

ext/date/tests/bug52113.phpt

Lines changed: 5 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var_dump($unser, $p);
3333

3434
?>
3535
--EXPECTF--
36-
object(DateInterval)#%d (16) {
36+
object(DateInterval)#%d (%d) {
3737
["y"]=>
3838
int(0)
3939
["m"]=>
@@ -48,24 +48,10 @@ object(DateInterval)#%d (16) {
4848
int(0)
4949
["f"]=>
5050
float(0)
51-
["weekday"]=>
52-
int(0)
53-
["weekday_behavior"]=>
54-
int(0)
55-
["first_last_day_of"]=>
56-
int(0)
5751
["invert"]=>
5852
int(0)
5953
["days"]=>
6054
int(0)
61-
["special_type"]=>
62-
int(0)
63-
["special_amount"]=>
64-
int(0)
65-
["have_weekday_relative"]=>
66-
int(0)
67-
["have_special_relative"]=>
68-
int(0)
6955
}
7056
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;}"
7157
\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"
7662
'i' => 0,
7763
's' => 0,
7864
'f' => 0.0,
79-
'weekday' => 0,
80-
'weekday_behavior' => 0,
81-
'first_last_day_of' => 0,
8265
'invert' => 0,
8366
'days' => 0,
84-
'special_type' => 0,
85-
'special_amount' => 0,
86-
'have_weekday_relative' => 0,
87-
'have_special_relative' => 0,
88-
))object(DateInterval)#%d (16) {
67+
))object(DateInterval)#%d (%d) {
8968
["y"]=>
9069
int(0)
9170
["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"
10079
int(0)
10180
["f"]=>
10281
float(0)
103-
["weekday"]=>
104-
int(0)
105-
["weekday_behavior"]=>
106-
int(0)
107-
["first_last_day_of"]=>
108-
int(0)
10982
["invert"]=>
11083
int(0)
11184
["days"]=>
11285
int(0)
113-
["special_type"]=>
114-
int(0)
115-
["special_amount"]=>
116-
int(0)
117-
["have_weekday_relative"]=>
118-
int(0)
119-
["have_special_relative"]=>
120-
int(0)
12186
}
12287
object(DatePeriod)#%d (6) {
12388
["start"]=>
@@ -134,7 +99,7 @@ object(DatePeriod)#%d (6) {
13499
["end"]=>
135100
NULL
136101
["interval"]=>
137-
object(DateInterval)#%d (16) {
102+
object(DateInterval)#%d (%d) {
138103
["y"]=>
139104
int(0)
140105
["m"]=>
@@ -149,31 +114,17 @@ object(DatePeriod)#%d (6) {
149114
int(0)
150115
["f"]=>
151116
float(0)
152-
["weekday"]=>
153-
int(0)
154-
["weekday_behavior"]=>
155-
int(0)
156-
["first_last_day_of"]=>
157-
int(0)
158117
["invert"]=>
159118
int(0)
160119
["days"]=>
161120
int(0)
162-
["special_type"]=>
163-
int(0)
164-
["special_amount"]=>
165-
int(0)
166-
["have_weekday_relative"]=>
167-
int(0)
168-
["have_special_relative"]=>
169-
int(0)
170121
}
171122
["recurrences"]=>
172123
int(3)
173124
["include_start_date"]=>
174125
bool(true)
175126
}
176-
object(DateInterval)#%d (16) {
127+
object(DateInterval)#%d (%d) {
177128
["y"]=>
178129
int(7)
179130
["m"]=>
@@ -188,24 +139,10 @@ object(DateInterval)#%d (16) {
188139
int(2)
189140
["f"]=>
190141
float(0.876543)
191-
["weekday"]=>
192-
int(-1)
193-
["weekday_behavior"]=>
194-
int(-1)
195-
["first_last_day_of"]=>
196-
int(-1)
197142
["invert"]=>
198143
int(1)
199144
["days"]=>
200145
int(2400)
201-
["special_type"]=>
202-
int(0)
203-
["special_amount"]=>
204-
int(-1)
205-
["have_weekday_relative"]=>
206-
int(0)
207-
["have_special_relative"]=>
208-
int(0)
209146
}
210147
object(DatePeriod)#%d (6) {
211148
["start"]=>
@@ -222,7 +159,7 @@ object(DatePeriod)#%d (6) {
222159
["end"]=>
223160
NULL
224161
["interval"]=>
225-
object(DateInterval)#%d (16) {
162+
object(DateInterval)#%d (%d) {
226163
["y"]=>
227164
int(0)
228165
["m"]=>
@@ -237,24 +174,10 @@ object(DatePeriod)#%d (6) {
237174
int(0)
238175
["f"]=>
239176
float(0)
240-
["weekday"]=>
241-
int(0)
242-
["weekday_behavior"]=>
243-
int(0)
244-
["first_last_day_of"]=>
245-
int(0)
246177
["invert"]=>
247178
int(0)
248179
["days"]=>
249180
int(0)
250-
["special_type"]=>
251-
int(0)
252-
["special_amount"]=>
253-
int(0)
254-
["have_weekday_relative"]=>
255-
int(0)
256-
["have_special_relative"]=>
257-
int(0)
258181
}
259182
["recurrences"]=>
260183
int(3)

0 commit comments

Comments
 (0)
0