Re: PHP 4.0 Bug #7659: Class variables get confused

From: Date: Mon, 06 Nov 2000 11:43:41 +0000
Subject: Re: PHP 4.0 Bug #7659: Class variables get confused
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-37252@lists.php.net to get a copy of this message
On Mon, 6 Nov 2000, Lars Torben Wilson wrote: >Those dollar signs shouldn't be there; the syntax you want for this >is '$this->one = $a', etc. > >What's happening above is that $this->$varname is an allowed syntax, >but with a different meaning. When PHP sees $this->$varname, it >evaluates $varname to find out what the name of the desired member is, >then evaluates the rest of it. So, for instance, if $varname == 'one', >then $this->$varname = 'Bob' would be interpreted as $this->one = >'Bob'. Since you haven't assigned anything to $one or $two, it's >interpreting the name to be NULL (a weird but possible thing in PHP). > >Insert the following lines at the end of Three() to see what I mean: > > $null = NULL; > echo "NULL is " . $this->$null . "<br>\n"; > > >Hope this helps, > >Torben This helps a lot; thank you -- I appear to have gotten a little confused when I skimmed the user comments in the manual on classes and objects. Thank you very much! Alex Wilkins

« previous php.dev (#37252) next »