PHP 4.0 Bug #10031: Stange behaviour in for loop with negative values

From: Date: Tue, 27 Mar 2001 22:15:30 +0000
Subject: PHP 4.0 Bug #10031: Stange behaviour in for loop with negative values
Groups: php.dev 
Request: Send a blank email to php-dev+get-50100@lists.php.net to get a copy of this message
From: php@suares.nl Operating system: Debian Linux 2.2 PHP version: 4.0.3pl1 PHP Bug Type: Variables related Bug description: Stange behaviour in for loop with negative values Hi, I tried to do something which was not really weird, but the the output astounded me. I tried to get opinions of two of my friends on this, but they didn't really help. I feel really stupid, because this looks much more like one of my programming errors then a bug. I tried to execute this script: <? echo "<H1>Start Day = $start_day,View_Days=$view_days</H1>"; for ($itchy = $start_day; $itchy <= ($start_day+$view_days);$itchy++) { $this_mktime=mktime(0,0,0,date("m"),date("d")+$itchy,date("Y")); echo date("D j M",$this_mktime)."<BR>\n"; } ?> I saved it in a file called test.php and called it from a website. like this: www.yoursite/test.php?start_day=4&view_days=10 The output was, as expected: Start Day = 4, View_Days= 10 Sun 1 Apr Mon 2 Apr Tue 3 Apr Wed 4 Apr Thu 5 Apr Fri 6 Apr Sat 7 Apr Sun 8 Apr Mon 9 Apr Tue 10 Apr Wed 11 Apr (Ok, it shows 11 days, but what the heck). Now, I tried to do this with some date in the past: www.yoursite/test.php?start_day=-2&view_days=10 The output is an endless loop with starts with this: Start Day = -2, View_Days= 10 Mon 26 Mar Sun 25 Mar Sat 24 Mar Fri 23 Mar Thu 22 Mar Wed 21 Mar Tue 20 Mar Mon 19 Mar Wed 28 Mar Tue 27 Mar Mon 26 Mar Sun 25 Mar Sat 24 Mar Fri 23 Mar Thu 22 Mar Wed 21 Mar Tue 20 Mar Mon 19 Mar Wed 28 Mar Tue 27 Mar Mon 26 Mar Sun 25 Mar Sat 24 Mar Fri 23 Mar Thu 22 Mar Wed 21 Mar Like I said, i feel really stupid now. What am I overlooking ? Much regards, keep up the good work, Ace Suares -- Edit Bug report at: http://bugs.php.net/?id=10031&edit=1

« previous php.dev (#50100) next »