#12350 [Com]: Referencing multiple arrays in classes from inside methods doesn't work
| From: | sex-latin449 at hotmail dot com | Date: | Tue, 20 Jul 2004 15:11:28 +0000 |
| Subject: | #12350 [Com]: Referencing multiple arrays in classes from inside methods doesn't work | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-63063@lists.php.net to get a copy of this message | ||
ID: 12350
Comment by: sex-latin449 at hotmail dot com
Reported By: m dot stenzel at dragondezign dot de
Status: Bogus
Bug Type: Class/Object related
Operating System: W2K
PHP Version: 4.0.6
New Comment:
<a href=http://1000--interracialfi.da.ru>sex
latin</a>
Previous Comments:
------------------------------------------------------------------------
[2001-07-25 05:29:38] cynic@php.net
use $this->firstarray, not $this->$firstarray
------------------------------------------------------------------------
[2001-07-24 16:13:07] 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";
$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 this bug report at http://bugs.php.net/?id=12350&edit=1