Background: I have an existing class with static functions that I'd like to reuse for another part of the same project. The static functions use $_GET
, etc.
Here is the baffling code. First, the class:
<?php
// ./fakeapi/fakeapi.php
class FakeAPI {
static public function test (){
$var = '_GET';
${$var}['newVar'] = '123';
print_r($_GET);
}
}
And the file requiring it:
<?php
require_once 'fakeapi/fakeapi.php';
FakeAPI::test();
$var = '_GET';
${$var}['newVar'] = '123';
print_r($_GET);
prints:
Array
(
)
Array
(
[newVar] => 123
)
...and I have no idea why. It's not a scope issue, because if I set $_GET['newVar'] = '123';
in the class function, it works. Does anyone know what's going on here?