Date: 11/06/00
- Next message: Alexander Wilkins: "Re: [PHP-DEV] PHP 4.0 Bug #7659: Class variables get confused"
- Previous message: Thies C. Arntzen: "Re: [PHP-DEV] PHP 4.0.3 patches - resources"
- In reply to: awilkins <email protected>: "[PHP-DEV] PHP 4.0 Bug #7659: Class variables get confused"
- Next in thread: Alexander Wilkins: "Re: [PHP-DEV] PHP 4.0 Bug #7659: Class variables get confused"
- Reply: Alexander Wilkins: "Re: [PHP-DEV] PHP 4.0 Bug #7659: Class variables get confused"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
awilkins <email protected> writes:
> From: awilkins <email protected>
> Operating system: RedHat Linux 6.2
> PHP version: 4.0 Latest CVS (06/11/2000)
> PHP Bug Type: Scripting Engine problem
> Bug description: Class variables get confused
>
> When this script is run:
>
> <?php
> class Three {
> var $one, $two;
>
> function Three($a, $b) {
> echo "a is $a; b is $b<br>\n";
>
> $this->$one = $a;
^^^^
> echo "one is " . $this->$one . "; two is " . $this->$two . "<br>\n";
^^^^ ^^^^
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
> a is 1; b is 2
> one is 1; two is 1
> one is 2; two is 2
>
> For some reason, it appears as if the two separate variables $one
> and $two are pointing at the same thing. This doesn't appear to be
> a problem that is specific to the constructor, as it happens even if
> the function involved is only a normal function. It also occurs if
> the variables are modified outside of the class.
>
> I also found this bug in 4.0.3pl1, but have not tried any earlier
> version. The only module I compiled PHP with was pgsql, if it
> matters.
>
> Alex Wilkins
-- +----------------------------------------------------------------+ |Torben Wilson <torben <email protected>> Netmill iTech| |http://www.coastnet.com/~torben http://www.netmill.fi| |Ph: 1 250 383-9735 torben <email protected>| +----------------------------------------------------------------+-- 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>
- Next message: Alexander Wilkins: "Re: [PHP-DEV] PHP 4.0 Bug #7659: Class variables get confused"
- Previous message: Thies C. Arntzen: "Re: [PHP-DEV] PHP 4.0.3 patches - resources"
- In reply to: awilkins <email protected>: "[PHP-DEV] PHP 4.0 Bug #7659: Class variables get confused"
- Next in thread: Alexander Wilkins: "Re: [PHP-DEV] PHP 4.0 Bug #7659: Class variables get confused"
- Reply: Alexander Wilkins: "Re: [PHP-DEV] PHP 4.0 Bug #7659: Class variables get confused"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

