Page 1 of 1
[solved] Strange neverending loop with 'while'
Posted: Tue Nov 28, 2006 8:03 pm
by zeek
I'm going insane!!!
In PHP5 the while line just loops endlessly somehow, even if I put a die() statement in the loop. If I replace:
with a variable, then the die() statement works.
Is this some PHP5 bug?
Code: Select all
while (strtotime($interval, $date) > $base_day) {
// if I put die(); on this line it still loops endlessly!!!
$pay_day = strtotime($interval, $date);
}
Posted: Tue Nov 28, 2006 8:08 pm
by evilchris2003
well as soon as it gets above your > than theres no break you need 2 use the top value possible
and then use <= instead
Posted: Tue Nov 28, 2006 8:14 pm
by zeek
The die() statement should kill it though. It doesn't actually loop, it's just endlessly running the while line or something.
Even if I replace the strtotime() with a zero '0' it still loops endlessly.
Posted: Tue Nov 28, 2006 8:15 pm
by Ambush Commander
Works for me, using PHP 5.2.0 on w32.
Posted: Tue Nov 28, 2006 8:17 pm
by evilchris2003
have you tried replacing the variables with values that you may use at some point
or at the very least echoing the variable to check they are what you think they should be
Posted: Tue Nov 28, 2006 8:25 pm
by zeek
Yes I've echoed the values and they are correct. Thank you both for your help. I will just do as you suggested and rewrite it with variables. I was trying to keep it a slim as possible, but I just have to get this done. Thanks again.
Posted: Tue Nov 28, 2006 8:28 pm
by evilchris2003
im not suggesting keeping the values its just a good way to error test
as is echoing which you are doing
anyway Ambush got it going
Posted: Tue Nov 28, 2006 8:32 pm
by zeek
OMG the loop was happening after this bit of code. I apologize. I have been at this all day, I guess I'm fried. Thank you again for helping me work though it.
Posted: Tue Nov 28, 2006 8:42 pm
by evilchris2003
put [solved] on the front of the title so people know