From:             [EMAIL PROTECTED]
Operating system: W2K
PHP version:      4.0.6
PHP Bug Type:     Class/Object related
Bug description:  Referencing multiple arrays in classes from inside methods doesn't 
work

Configuration: IIS 4 dll with Win32 binaries

Okay I'm new to the game so forgive me a small mistake but I have tested
and reproduced this weird behavior for more than 6 hours.

A class wrapping multiple array variables doesn't allow to access both
arrays as individual references from inside a function.

The following code does not what I expected from the language:

class test {
  VAR $firstarray;  // defining one array
  VAR $secondarray; // defining another array
        
  function testit () {
    $i = 0;
    while ($i < 14) {
      $this->$firstarray[$i] = uniqid ("test", false);
          $this->$secondarray[$i] = uniqid ("different", false);
      echo "Set array #1, item $i to ".$this->$firstarray[$i]." and array
#2 to ".$this->$secondarray[$i]."\n";
          $i++;
        }
  }

  function doitlocal () {
    $i = 0;
    while ($i < 14) {
      $firstarray[$i] = uniqid ("test", false);
          $secondarray[$i] = uniqid ("different", false);
      echo "Set array #1, item $i to ".$firstarray[$i]." and array #2 to
".$secondarray[$i]."\n";
          $i++;
        }
  }
  
}

  $temp = new test;
  $temp->testit();
  echo "The (wrong) result shows that both arrays contain the same
data.\n\n";
  echo "Now lets do it local:\n";
  $temp->doitlocal();
  echo "With local variables everything works as expected.";

I expected the same result from both the testit() and doitlocal() methods
and that would be creating two distinctive arrays and accessing them later
in the script just with different values. This seems not to be possible if
the array is capsulated in the class.

I think i read the manual thorougly and haven't found a hint about this
behavior :(

-- 
Edit bug report at: http://bugs.php.net/?id=12350&edit=1


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to