Mantis Bugtracker

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0003822 [Quercus] block always 12-20-09 19:46 12-21-09 05:23
Reporter domdorn View Status public  
Assigned To
Priority normal Resolution open  
Status new   Product Version 4.0.2
Summary 0003822: Variable scoping issues in loops!!!!
Description I have lots of code like this:

    while(list($dnow, $nusernr, $stitle, $stext, $nuserguestbooknr,$nstatusnr) = $rSQLGetEntries->fetchRow() )
        unset($dnow, $nusernr, $stitle, $stext, $nuserguestbooknr,$nstatusnr);

where $rSQLGetEntries is a Pear::DB Object and fetchRow() is a method, returning an array (see [^] )

this code does not work, because the list expression is not implemented correctly OR the scoping of variables in Loops is broken!

I've narrowed it down to something like this (10 is the correct number of rows returned)

    for($i = 0; $i < 10; $i++)
        $res = $rSQLGetEntries->fetchRow();
        echo "<hr/>";
this correctly executes print_r on each of the 10 rows... however, as soon as I do this:
    for($i = 0; $i < 10; $i++)
        $res = $rSQLGetEntries->fetchRow();
        echo "<hr/>";
        $dnow = $res[0];
the code stops after the first loop execution
Additional Information
Attached Files

- Relationships

- Notes
12-21-09 05:23

I thought a bit about this and this came to my mind:

The problem here is, that $res is bound to an object that does not exist in the next iteration of the loop ... when using print_r, a copy of that object gets created, the first assignment from $res to $dnow works, because the object is still in memory, the loop finishes... in the next loop, quercus somehow tries to access the old data but thats invalid and stops.. if I copy the data first to an array and use it like this

$lResult = array();
while( $row = $rSQLGetEntries->fetchRow() )
  $lResult[] = $row;

I can iterate over $lResult the normal way, because the data in $row gets _copied_ into $lResult.

- Issue History
Date Modified Username Field Change
12-20-09 19:46 domdorn New Issue
12-21-09 05:23 domdorn Note Added: 0004362

Mantis 1.0.0rc3[^]
Copyright © 2000 - 2005 Mantis Group
28 total queries executed.
25 unique queries executed.
Powered by Mantis Bugtracker