php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16199 Loop not looping
Submitted: 2002-03-21 00:10 UTC Modified: 2002-05-04 01:12 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: paul79 at optonline dot net Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.1.2 OS: FreeBSD 4.5
Private report: No CVE-ID: None
 [2002-03-21 00:10 UTC] paul79 at optonline dot net
Please see below.  I have included all information possible that could be of assistance.  This looks possibly like, the array is too deep, or perhaps a type not being an int, but I honestly think it's something else.  I hope it's not me.  I've been staring at this for a long time and had other look at it.  :)  Thanks Paul


/* This is the output from print_r that in the function below */

Array ( [Domain] => www.test.com [Start IP] => 64.24.23.32 [End IP] => 6.23.23.23 [Netmask] => 255.255.255.255 [Number of Disks] => 2 [Disk Type] => ide [Enable Raid] => Y [Disk Sizes] => Array ( [0] => Array ( [SIZE] => 40 [/] => 39 [Swap] => 1 ) [1] => Array ( [SIZE] => 40 [/home] => 40 ) ) ) 

function do_last(){
    global $SESSION_DATA

    /* See above for output -- Used for debugging 
    print_r($SESSION_DATA); */

    while(list($key,$value) = each($SESSION_DATA)){
         print $key . "<br>";

         /* Handle a special key */
         if($key == "Disk Sizes"){

                 /* This following code should output 2 values that are stored in the array, but if a un-comment out "print $a", the value is initially 2.  What happened to it being 0? */ 
                 for($a=0;$a<count($SESSION_DATA[$key]);$a++){
                          //print $a;
                          print $SESSION_DATA[$key][$a]["SIZE"] . "<br>";
                  }
          }
          else{
                  print $value . "<br>";
          }
     }

Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-03-21 00:30 UTC] cnewbill@php.net
Can't reproduce on Linux using 4.0.6/4.1.0/4.2.0 or Windows XP w/4.0.6.

I get 0 and 1 as expected.  Of course without the original data I can't figure anything out I had to rebuild the data from your print_r output to this.

$SESSION_DATA = array(
"Domain" => "www.test.com",
"Start IP" => "64.24.23.32",
"End IP" => "6.23.23.23",
"Netmask" => "255.255.255.255",
"Number of Disks" => 2,
"Disk Type" => "ide",
"Enable Raid" => "Y",
"Disk Sizes" => array(
        0 => array ("SIZE" => 40,
                "/" => 39,
                "Swap" => 1),
        1 => array("SIZE" => 40,
                "/home" => 40)
        )
);

Yeah, it probably is you ;)
Here's my output

Domain<br>www.test.com<br>
Start IP<br>64.24.23.32<br>
End IP<br>6.23.23.23<br>
Netmask<br>255.255.255.255<br>
Number of Disks<br>2<br>
Disk Type<br>ide<br>
Enable Raid<br>Y<br>
Disk Sizes<br>040<br>
140<br>

-Chris
 [2002-03-21 16:03 UTC] paul79 at optonline dot net
The way you set it up looks correct, but when I print the value of the inner loop.  It does, in fact only print the value of 2, then stops.  I can continue to reproduce this on 2 of my BSD machines, and quite honestly, the code does look ok.

--Paul
 [2002-03-21 18:04 UTC] paul79 at optonline dot net
Hey guys,
     I have try statically filling the var, and the problem does indeed still persist.  Here's recap:

FreeBSD 4.5
php 4.1.2
apache 1.3.23

My configure line:

 './configure' '--with-apxs=/usr/local/sbin/apxs' '--with-config-file-path=/usr/local/etc' '--enable-versioning' '--with-system-regex' '--disable-debug' '--enable-track-vars' '--without-gd' '--without-mysql' '--with-zlib' '--with-mysql=/usr/local' '--enable-sockets' '--enable-trans-sid' '--prefix=/usr/local'

And of coarse, the above code.
 [2002-05-03 09:47 UTC] andy at mindcomet dot com
i have an even simpler example:

        for ($i=0; $i<60; $i++);
        {
            echo $i . "<br>";
        }

this is producing only one iteration throught the loop!  
the result of this loop is visible at http://www.gleep.org/
test/index.php and the loop visible at http://
www.gleep.org/test/index.phps

i'm running 4.2.0 on apache 1.3.24 on a linux box.  i've 
tried it on 4.1.2 and i get the same thing!

i know i've used for loops before and not had this 
problem...
 [2002-05-03 10:02 UTC] cynic@php.net
what about the semicolon after for (...) ?

 [2002-05-03 13:53 UTC] paul79 at optonline dot net
This is a bug.  I've had mutiple people come up with the same result.  Let's stop being lazy, and really try to duplicate this.  Actually, I already rewrote my code, to account for this.  Might as well, leave it as "BOGUS".  Yeah right.
 [2002-05-03 14:05 UTC] mfischer@php.net
Reopening, as the original problem is not yet resolved.

Please provide a *short* and *self-contained* example so we can reproduce it.
 [2002-05-03 14:07 UTC] sander@php.net
This is NOT a bug!
for ($i=0; $i<60; $i++);
                      ^^^
You don't want that semi-colon there. Remove it and it works as expected!

Loops are working perfectly: I use loops more than you write PHP code and they always work for me! RTFM!
 [2002-05-03 15:10 UTC] sander@php.net
Sorry, this is something else. Reopening and waiting for your sample script.
 [2002-05-03 16:28 UTC] paul79 at optonline dot net
sander, RTFM?  Apology accepted.  :)  Like I had stated previously, I have changed my code to work around this "bug".  I guess I should've kept the original.  I do not have other examples.  Sorry.

Best of luck!!
Paul
 [2002-05-04 01:12 UTC] mfischer@php.net
Not able to provide a sample? Ok, closing then. Re-open if you have one
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Aug 18 19:01:28 2024 UTC