Why are there two signs of the $$ infront variable?

Possible duplicate:
what does $$ mean in PHP?

I recently needed to make changes to the application and came across this $pageObject->createPageContent($$templateName);

The method looked like this:

function createPageContent($page_content_html) {
        $this->page_content = $page_content_html;
    }

My question is that when I deleted one character of the $ infront variable, I got a different result, as with double $$. Why is there one $ extra sign? What is the purpose for this?

+3
source share
4 answers

$$means variable variable in PHP.

This is an easy way to refer to an existing variable using a string.

Here is an example:

$someVar = 'something';

$varname = 'someVar';

echo $$varname; //something

, $templateName , , $, PHP . IMHO.

+7

$$ . $templateName , .

${$templateName}

,

$templateName = "hello";
$hello = "world";

echo $$templateName;
//-> "world"

http://php.net/manual/en/language.variables.variable.php

+4

When you use two $$, this means that the variable name is actually valid.

$animal = "cow";

$cow = "moo";

echo $$animal;

//Prints 'moo'
+1
source

This way you can dynamically access variables.

There is a great description that can be found on php.net .

0
source

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


All Articles