|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #12350 Referencing multiple arrays in classes from inside methods doesn't work
Submitted: 2001-07-24 16:13 UTC Modified: 2001-07-25 05:29 UTC
From: m dot stenzel at dragondezign dot de Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 4.0.6 OS: W2K
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
9 + 35 = ?
Subscribe to this entry?

 [2001-07-24 16:13 UTC] m dot stenzel at dragondezign dot de
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";

  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";

  $temp = new test;
  echo "The (wrong) result shows that both arrays contain the same data.\n\n";
  echo "Now lets do it local:\n";
  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 :(


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-07-25 05:29 UTC]
use $this->firstarray, not $this->$firstarray
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 09:01:27 2024 UTC