Is the dollar sign in a variable variable considered an dereference operator?

I showed someone how you can create variable variables of variables in PHP (I would recommend using NEVER, this is a terrible practice, and you are a bad person if you use variable variables in the actual production code), and they asked if in this case the sign The dollar acted as the dereferencing operator.

In fact, it does not create a link to other variables, so I really do not see the deref function in it. The documentation for variable variables doesn't even mention references at all.

Who is right? I don’t think variable variables create links, and therefore the dollar sign is not an dereference operator.

Here is a sample code for the pleasure of your viewing (or pain, given the content):

<?php $a = 'c'; $b = 'a'; $c = 'hello'; echo($$$b); //hello 
+6
source share
2 answers

The dollar sign in a variable variable is considered an dereference operator?

Not. PHP does not have a dereference operator.

Variables should not be considered dereferencing, but rather access to the character tree through a string. For instance:

 $bar = 1; echo ${'bar'}; 

You can do this dynamically using a variable instead of a string literal:

 $bar = 1; $foo = 'bar'; echo ${$foo}; 

PHP syntax allows you to remove curly braces, but still the issue is accessing the character table through a string. No links / dereferencing.

+4
source

No, this is not a DE link to anything .... if anything at all, it refers to the link of the stored variable name to refer to the stored value of the stored variable .... kind of double link or link link .... .de-ref will mean that one variable was part of a subset of the other.

0
source

Source: https://habr.com/ru/post/896747/


All Articles