[solved] Strange neverending loop with 'while'

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
zeek
Forum Commoner
Posts: 48
Joined: Mon Feb 27, 2006 7:41 pm

[solved] Strange neverending loop with 'while'

Post 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:

Code: Select all

strtotime($interval, $date)
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);

        }
Last edited by zeek on Tue Nov 28, 2006 8:43 pm, edited 1 time in total.
User avatar
evilchris2003
Forum Contributor
Posts: 106
Joined: Sun Nov 12, 2006 6:43 am
Location: Derby, UK

Post 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
User avatar
zeek
Forum Commoner
Posts: 48
Joined: Mon Feb 27, 2006 7:41 pm

Post 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.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Works for me, using PHP 5.2.0 on w32.
User avatar
evilchris2003
Forum Contributor
Posts: 106
Joined: Sun Nov 12, 2006 6:43 am
Location: Derby, UK

Post 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
User avatar
zeek
Forum Commoner
Posts: 48
Joined: Mon Feb 27, 2006 7:41 pm

Post 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.
User avatar
evilchris2003
Forum Contributor
Posts: 106
Joined: Sun Nov 12, 2006 6:43 am
Location: Derby, UK

Post 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
User avatar
zeek
Forum Commoner
Posts: 48
Joined: Mon Feb 27, 2006 7:41 pm

Post 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.
User avatar
evilchris2003
Forum Contributor
Posts: 106
Joined: Sun Nov 12, 2006 6:43 am
Location: Derby, UK

Post by evilchris2003 »

put [solved] on the front of the title so people know
Post Reply