@@ -83,6 +83,13 @@ class ChronosInterval extends DateInterval
83
83
*/
84
84
const PHP_DAYS_FALSE = -99999 ;
85
85
86
+ /**
87
+ * Whether or not this object was created in HHVM
88
+ *
89
+ * @var bool
90
+ */
91
+ protected $ isHHVM = false ;
92
+
86
93
/**
87
94
* Determine if the interval was created via DateTime:diff() or not.
88
95
*
@@ -107,6 +114,7 @@ protected static function wasCreatedFromDiff(DateInterval $interval)
107
114
*/
108
115
public function __construct ($ years = 1 , $ months = null , $ weeks = null , $ days = null , $ hours = null , $ minutes = null , $ seconds = null )
109
116
{
117
+ $ this ->isHHVM = defined ('HHVM_VERSION ' );
110
118
$ spec = static ::PERIOD_PREFIX ;
111
119
112
120
$ spec .= $ years > 0 ? $ years . static ::PERIOD_YEARS : '' ;
@@ -238,30 +246,39 @@ public function __get($name)
238
246
{
239
247
switch ($ name ) {
240
248
case 'years ' :
241
- return $ this ->y ;
249
+ return $ this ->isHHVM ? parent :: __get ( ' y ' ) : $ this -> y ;
242
250
243
251
case 'months ' :
244
- return $ this ->m ;
252
+ return $ this ->isHHVM ? parent :: __get ( ' m ' ) : $ this -> m ;
245
253
246
254
case 'dayz ' :
247
- return $ this ->d ;
255
+ return $ this ->isHHVM ? parent :: __get ( ' d ' ) : $ this -> d ;
248
256
249
257
case 'hours ' :
250
- return $ this ->h ;
258
+ return $ this ->isHHVM ? parent :: __get ( ' h ' ) : $ this -> h ;
251
259
252
260
case 'minutes ' :
253
- return $ this ->i ;
261
+ return $ this ->isHHVM ? parent :: __get ( ' i ' ) : $ this -> i ;
254
262
255
263
case 'seconds ' :
256
- return $ this ->s ;
264
+ return $ this ->isHHVM ? parent :: __get ( ' s ' ) : $ this -> s ;
257
265
258
266
case 'weeks ' :
259
- return (int )floor ($ this ->d / ChronosInterface::DAYS_PER_WEEK );
267
+ return (int )floor (( $ this ->isHHVM ? parent :: __get ( ' d ' ) : $ this -> d ) / ChronosInterface::DAYS_PER_WEEK );
260
268
261
269
case 'daysExcludeWeeks ' :
262
270
case 'dayzExcludeWeeks ' :
263
- return $ this ->d % ChronosInterface::DAYS_PER_WEEK ;
264
-
271
+ return $ this ->dayz % ChronosInterface::DAYS_PER_WEEK ;
272
+ case 'days ' :
273
+ return $ this ->isHHVM ? parent ::__get ('days ' ) : $ this ->days ;
274
+ case 'y ' :
275
+ case 'm ' :
276
+ case 'd ' :
277
+ case 'h ' :
278
+ case 'i ' :
279
+ case 's ' :
280
+ case 'invert ' :
281
+ return parent ::__get ($ name );
265
282
default :
266
283
throw new InvalidArgumentException (sprintf ("Unknown getter '%s' " , $ name ));
267
284
}
@@ -279,32 +296,41 @@ public function __set($name, $val)
279
296
{
280
297
switch ($ name ) {
281
298
case 'years ' :
282
- $ this ->y = $ val ;
299
+ $ this ->isHHVM ? parent :: __set ( ' y ' , $ val ) : $ this -> y = $ val ;
283
300
break ;
284
301
285
302
case 'months ' :
286
- $ this ->m = $ val ;
303
+ $ this ->isHHVM ? parent :: __set ( ' m ' , $ val ) : $ this -> m = $ val ;
287
304
break ;
288
305
289
306
case 'weeks ' :
290
- $ this ->d = $ val * ChronosInterface::DAYS_PER_WEEK ;
307
+ $ val = $ val * ChronosInterface::DAYS_PER_WEEK ;
308
+ $ this ->isHHVM ? parent ::__set ('d ' , $ val ) : $ this ->d = $ val ;
291
309
break ;
292
310
293
311
case 'dayz ' :
294
- $ this ->d = $ val ;
312
+ $ this ->isHHVM ? parent :: __set ( ' d ' , $ val ) : $ this -> d = $ val ;
295
313
break ;
296
314
297
315
case 'hours ' :
298
- $ this ->h = $ val ;
316
+ $ this ->isHHVM ? parent :: __set ( ' h ' , $ val ) : $ this -> h = $ val ;
299
317
break ;
300
318
301
319
case 'minutes ' :
302
- $ this ->i = $ val ;
320
+ $ this ->isHHVM ? parent :: __set ( ' i ' , $ val ) : $ this -> i = $ val ;
303
321
break ;
304
322
305
323
case 'seconds ' :
306
- $ this ->s = $ val ;
324
+ $ this ->isHHVM ? parent ::__set ('s ' , $ val ) : $ this ->s = $ val ;
325
+ break ;
326
+
327
+ case 'invert ' :
328
+ $ this ->isHHVM ? parent ::__set ('invert ' , $ val ) : $ this ->invert = $ val ;
307
329
break ;
330
+ default :
331
+ if ($ this ->isHHVM ) {
332
+ parent ::__set ($ name , $ val );
333
+ }
308
334
}
309
335
}
310
336
0 commit comments