# Weird.

- Thread: https://externals.io/message/7088
- Original archive: https://news-web.php.net/php.internals/7088
- Started by John Coggeshall on 2004-01-14T09:33:13+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #7088 — John Coggeshall — 2004-01-14T09:33:13+00:00

URL: https://externals.io/message/7088#7088

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 :)

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/
-=~=--=~=--=~=--=~=--=~=--=~=--=~=--=~=--=~=--=~=--=~=--=~=

---

## #7089 — messju mohr — 2004-01-14T10:09:42+00:00

URL: https://externals.io/message/7088#7089 · In reply to: #7088

> 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/
> -=~=--=~=--=~=--=~=--=~=--=~=--=~=--=~=--=~=--=~=--=~=--=~=

---

## #7090 — Zeev Suraski — 2004-01-14T12:02:59+00:00

URL: https://externals.io/message/7088#7090 · In reply to: #7088

At 11:33 14/01/2004, 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 :)
>
>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";
>
>              }
>         }
>
>?>

I don't see anything odd in here.  All of the assignments, except for the 
first one ('A'), assign to $this->"" (because $myvar, ${'myvar'} (which is 
the same as $myvar) and ${'$myvar'} (which is basically $"") are all non 
existent variables which implicitly evaluate to "".  Try to turn on E_ALL, 
it should give you some insight...

Zeev
