Mantis - Quercus
Viewing Issue Advanced Details
1233 minor always 07-05-06 20:16 07-17-06 19:26
koreth  
ferg  
normal  
closed 3.0.20  
fixed  
none    
none 3.0.20  
0001233: each() doesn't populate class member variables in recursive methods
PHP code:

<?php
class Test {
        function doTest(& $foo) {
                list($this->key,) = each($foo);
                error_log($this->key);
                // The key should be empty after the first fetch
                if ($this->key)
                        $this->doTest($foo);
        }
}

$obj = new Test;
$foo = array();
$foo[1] = 'x';

$obj->doTest($foo);
?>

Under regular PHP, this prints "1" and a blank line to standard error and terminates. Under Quercus, it keeps printing "1" and calling itself until it dies with a stack overflow exception.

Changing $this->key to just $key makes the problem go away. So does using a regular function (rather than a class method). So does making the method non-recursive and calling it twice from the main part of the code. However, using a member variable for the array rather than passing it as a parameter to the test method still exhibits the bug (so it's not, apparently, a bug in the parameter passing.)

Notes
(0001404)
ferg   
07-17-06 19:26   
php/03lb