ID: 12350
Updated by: cynic
Reported By: [EMAIL PROTECTED]
Old Status: Open
Status: Bogus
Bug Type: Class/Object related
Operating System: W2K
PHP Version: 4.0.6
New Comment:
use $this->firstarray, not $this->$firstarray
Previous Comments:
------------------------------------------------------------------------
[2001-07-24 16:13:07] [EMAIL PROTECTED]
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
--
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]