I have the following code to see if the allotted time has passed.
For my demo it should all evaluate to false and nothing should happen.
What happens ever is that it parses to true, even inf I compare it with >=
Why do I get this strange behaviour?
$data = '[{"ip":"80.61.150.173","endtime":1343988643},{"ip":"80.61.150.173","endtime":1343988649},{"ip":"80.61.150.173","endtime":1343988650},{"ip":"80.61.150.173","endtime":1343988664},{"ip":"80.61.150.173","endtime":1343988682},{"ip":"80.61.150.173","endtime":1343988723}]';
$json = json_decode($data,true);
foreach($json as $key => $obj)
{
var_dump($obj);
echo "<BR>";
var_dump(time());
echo "<BR>";
if($obj['endtime'] <= time());
{
echo "<BR>bliep<P>";
}
}
This code evaluates to this result:
array(2) { [“ip”]=> string(13) “80.61.150.173” [“endtime”]=>
int(1343988643) }
int(1343981967)bliep array(2) { [“ip”]=> string(13) “80.61.150.173” [“endtime”]=>
int(1343988649) }
int(1343981967)bliep
array(2) { [“ip”]=> string(13) “80.61.150.173” [“endtime”]=>
int(1343988650) }
int(1343981967)bliep
array(2) { [“ip”]=> string(13) “80.61.150.173” [“endtime”]=>
int(1343988664) }
int(1343981967)bliep
array(2) { [“ip”]=> string(13) “80.61.150.173” [“endtime”]=>
int(1343988682) }
int(1343981967)bliep
array(2) { [“ip”]=> string(13) “80.61.150.173” [“endtime”]=>
int(1343988723) }
int(1343981967)bliep
As you can see, there are all blieps there that shouldn’t be there.
The timestamps are ints, the current time is smaller than the saved time.
It should compare easily, but it evaluates always to true, whilst now is < than the stored timestamp.
What’s going on here?
It’s not my server because this code also evaluates to true on http://writecodeonline.com/php/
I believe there’s a typo
;at the end if yourifstatement.Should’ve been
instead of