Re: [PHP-DEV] PHP 4.0 Bug #7659: Class variables get confused From: Alexander Wilkins (awilkins <email protected>)
Date: 11/06/00

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

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: php-dev-unsubscribe <email protected>
For additional commands, e-mail: php-dev-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>