1

OK I think I have found a pretty strange bug.

I have 2 objects of the type DateInterval and is trying to evaluate if one is bigger than the other - however this fails unless I do a var_dump() on both objects first!

1st example

//** 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;      
}

2nd example

//** 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;      
}

3rd example

//** 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;      
}

I'm getting a bit frustrated...

....additional info

these are the var_dump() - they are run in a foreach loop so the $sum_off variable might hold values bigger or smaller than this.

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)
}
Ulrik Pedersen
  • 73
  • 1
  • 12
  • Can you provide the `var_dump` output for each? – Kevin Stich Dec 09 '16 at 23:55
  • The problem with your question is, is that when this is interpreted `var_dump()` has no relation to your if statement. So as @KevinStich suggested, you cannot really compare objects like this in PHP. – Xorifelse Dec 09 '16 at 23:57
  • 1
    You don't need to edit your question. It's a duplicate. – miken32 Dec 10 '16 at 00:07
  • 1
    Agree on the probable duplicate. Very weird behavior -- I would have said the question definitely needed editing because it can't possibly be the case. Nice ID on the duplicate @KevinStich – Anne Gunn Dec 10 '16 at 00:08
  • Strange that I did not find that post before - have been struggeling most of an hour with this :/ – Ulrik Pedersen Dec 10 '16 at 00:11

0 Answers0