In PHP ...
var_dump(${'_GET'}); // array(0) { } - #1
$var = '_GET';
var_dump(${$var}); // array(0) { } - #2
function test() {
var_dump(${'_GET'}); // array(0) { } - #3
$var = '_GET';
var_dump(${$var}); // NULL - #4
}
test();
What happen?
Some predefined variables in PHP are "superglobals", which means that they are always accessible, regardless of scope - and you can access them from any function, class or file without having to do anything special.
PHP $_REQUEST is a PHP super global variable which is used to collect data after submitting an HTML form. The example below shows a form with an input field and a submit button. When a user submits the data by clicking on "Submit", the form data is sent to the file specified in the action attribute of the <form> tag.
PHP $_POST is a PHP super global variable which is used to collect form data after submitting an HTML form with method="post". $_POST is also widely used to pass variables.
E.g. if you're about to access a variable inside a function that's defined outside you'll need to use the global keyword to make it accessible in the function. $GLOBALS is a superglobal array. Superglobal simply means that it is available in all scopes throughout a script without the need of using the global keyword.
It's not a bug, it's a feature:
Warning
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With