Today I met such a terrible situation.
It seems this bug is related to PHP
.
I'm trying to access to $_SERVER
or another super global variables but from string name.
var_dump(${"_SERVER"}); // working
$var_name = "_SERVER";
var_dump(${$var_name}); // Notice</b>: Undefined variable: _SERVER in...
And this will happen only with a global variable.
What is going on there? Can someone explain this situation.
variable variables cannot be used with PHP's Superglobal arrays within functions or class methods. Demo
Refer to php doc Variable variables
Please note that variable variables cannot be used with PHP's Superglobal arrays within functions or class methods. The variable $this is also a special variable that cannot be referenced dynamically.