Goofy interactions between $this and vars in classs. 4.1.0

From: Date: Mon, 17 Dec 2001 08:05:15 +0000
Subject: Goofy interactions between $this and vars in classs. 4.1.0
Groups: php.general 
Request: Send a blank email to php-general+get-77917@lists.php.net to get a copy of this message
Hi! I'm having some goofy interactions between $this pointers in classes and variables. Case in Point: if I have the following code: <?php class Y { var $children; function addValue($in_value) { $this->children[] = $in_value; } function Y() { } function Zabba() { $this->addValue("asdfasdfasdf"); } } $abc = new Y(); $abc->Zabba(); var_dump($abc->children); ?> I will correctly get on output, an array with one item in it. However, if I Change the Zabba function to: function Zabba() { $localVariable = $this; $localVariable->addValue("asdfasdfasdf"); } Then I will get on output, a NULL array. Why is this? Is there any particular reason this happens? thanks, mark.

« previous php.general (#77917) next »