PHP DateInterval比较错误?

时间:2016-12-09 23:53:14

标签: php debugging dateinterval

好吧我觉得我发现了一个非常奇怪的错误。

我有2个DateInterval类型的对象,并且正在尝试评估一个是否比另一个更大 - 但是除非我首先在两个对象上执行var_dump(),否则这会失败!

第一个例子

//** THIS WORKS AND EVALUATES TO TRUE WHEN SUPPOSED TO!

var_dump($sum_off);
var_dump($n_off);

if($sum_off >= $n_off){
    $running = FALSE;
    $sum_on = new DateInterval('P0000-00-00T00:00:00');
    $sum_off = new DateInterval('P0000-00-00T00:00:00');
    $first_off = NULL;      
}

第二个例子

//** THIS NEVER EVALUATES TO TRUE!

var_dump($n_off);

if($sum_off >= $n_off){
    $running = FALSE;
    $sum_on = new DateInterval('P0000-00-00T00:00:00');
    $sum_off = new DateInterval('P0000-00-00T00:00:00');
    $first_off = NULL;      
}

第3个例子

//** THIS ALWAYS EVALUATES TO TRUE!

var_dump($sum_off);

if($sum_off >= $n_off){
    $running = FALSE;
    $sum_on = new DateInterval('P0000-00-00T00:00:00');
    $sum_off = new DateInterval('P0000-00-00T00:00:00');
    $first_off = NULL;      
}

我有点沮丧......

....其他信息

这些是var_dump() - 它们在foreach循环中运行,因此$ sum_off变量可能包含大于或小于此值的值。

object(DateInterval)#17 (15) {
["y"]=>
int(0)
["m"]=>
int(0)
["d"]=>
int(0)
["h"]=>
int(9)
["i"]=>
int(59)
["s"]=>
int(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)#22 (15) {
["y"]=>
int(0)
["m"]=>
int(0)
["d"]=>
int(0)
["h"]=>
int(0)
["i"]=>
int(10)
["s"]=>
int(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)
}

0 个答案:

没有答案