On Wed, Jan 14, 2004 at 04:33:13AM -0500, John Coggeshall wrote:
> I know that this issue to some extent or another has been brought up
> before, but I just wanted to make sure that this is really how things
> are supposed to work... Apparently the statements setting B C and D
> are all equivalent.
> 
> This could be absolutely bogus, but I thought maybe someone could
> explain briefly why if it is :)

"B" and "C" are equivalent but "D" is somethig else.

"B" and "C" set the property named by the value of $myvar.
in "D" the variable-name is '$myvar' (not 'myvar').

if you set

$myvar = "foo";
${'$myvar'} = "bar";

then "B" and "C" will set $this->foo, but "D" will set $this->bar.

it's not that bogus.

greetings
messju


> John
> 
> <?php
>         class weird {
> 
>               var $myvar;
> 
>               function __construct() {
> 
>               $this->myvar = "A";
>               $this->$myvar = "B";
>               $this->${'myvar'} = "C";
>               $this->${'$myvar'} = "D";
> 
>               echo 'this->myvar: '.$this->myvar."\n";
>               echo 'this->$myvar: '.$this->$myvar."\n";
>               echo 'this->${\'myvar\'}: '.$this->${'myvar'}."\n";
>               echo 'this->${\'$myvar\'}: '.$this->${'$myvar'}."\n";
>               echo 'this->$$$$$$$myvar: '.$this->$$$$$$$myvar."\n";
>               echo 'this->$$$$$$${\'$$$myvar\'}: ' . 
>                     $this->$$$$$$${'$$$myvar'}."\n";
> 
>              }
>         }
> 
> ?>
> -- 
> -=~=--=~=--=~=--=~=--=~=--=~=--=~=--=~=--=~=--=~=--=~=--=~=-
> John Coggeshall                   http://www.coggeshall.org/
> The PHP Developer's Handbook    http://www.php-handbook.com/
> -=~=--=~=--=~=--=~=--=~=--=~=--=~=--=~=--=~=--=~=--=~=--=~=-
> 
> -- 
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to