Class variable unexpected behavior

From: Date: Sat, 15 May 2004 10:24:02 +0000
Subject: Class variable unexpected behavior
Groups: php.general 
Request: Send a blank email to php-general+get-186332@lists.php.net to get a copy of this message
I am sure this is something I'm doing wrong, but I just can't see it. I have the following in my test.php file: <html> <head> </head> <body> <?php class test { var $a; var $b = "goodbye"; function c($arg) { $this->$a = $arg; echo "<p>a = " . $this->$a . "</p>\n"; echo "<p>b = " . $this->$b . "</p>\n"; } } $d = new test; $d->c("hello"); ?> </body> </html> When I load the page, I expect to see the following output: a = hello b = goodbye Instead, what I'm seeing is: a = hello b = hello It seems that all variables in the class are taking the value of the last assignment to any other variable in the class. Can anyone tell me what mistake I'm making? I'm using PHP 4.3.4 on an up-to-date Fedora Core 1 system. Much thanks, -Richard

« previous php.general (#186332) next »