Tuesday, 20 November 2018

variable variables - what is "$$" in PHP



I saw this code




if (is_null($$textVarName)) {
$$textVarName = $_defaultTexts[$type];
}


what is code "$$" ?


Answer



It's evil is what it is.




That will take the value that's in $textVarName and use that as a variable name. For example:



$foo = 'hello';
$hello = 'The Output';
echo $$foo; // displays "The Output"

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...