session – Calling _SESSION from variable variables in php doesn't work php

Exception or error:

I have a system that loads variables from the DB and then calls them using the variable variables feature of PHP. The weird thing I ran into is that when calling the session this way:

$some_var = ${'_SESSION'}['some_key']; // Works!

It works, but if I call the session by storing the string in a variable it returns a Undefined variable: _SESSION error:

$var_var = '_SESSION';
$some_var = ${$var_var}['some_key']; // Doesn't work

The thing is that I call the _SESSION variable name from DB so it has to be stored in another variable berfore calling to keep things modular, does someone know what is happening here? It works for other variable except _SESSION (still didn’t try for _POST or others but I guess it has something to do with language specific globals like this).

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *