This task is a common XY Problem.
It is poor design to create a function/method which needs access to data not declared in the function/method signature.
This is a code smell.
No modern code containing custom functions should be passing data into the limited scope using global or super-globals (e.g. $GLOBALS, $_POST, $_GET, $_REQUEST, $_SESSION). In fact, for maximim utility, you should never write a function signature or body which contains global variables. Functions should be completely ignorant of where their input data was sourced from -- that is business of the calling script, not the function being called.
Ideally, you pass all required data as parameters to your function. If you cannot (or choose not to) return data from your function, then you can modify any number of parameters by reference (add & before the parameter(s) in the signature).
Do not be tempted to reduce the parameter count. It is too common to see scripts which have the database connection as global $mysqli; as the first line in the function body -- don't do that.
Also ensure that functions only do one thing. If a function needs to do two things, break the function down into two child functions called by the parent function and pass required data where needed. This will improve maintainability.
We should only see snippets like:
Returning data:
function foo(bool $bar): bool
{
return !$bar;
}
$bar = false;
var_export(foo($bar)); // true
Or modifying data by reference:
function foo(bool &$bar): void
{
$bar = !$bar;
}
$bar = false;
foo($bar);
var_export($bar); // true
There might be some edge cases where using a combination of the two above approach seems suitable -- but endeavour to avoid such structures as much as possible.
As a related side step on this topic, if you need to modify data within a function of which you do not have control of the signature, pass the variable into the function scope by reference use (&$data). If you need to pass in but not modify the passed in data, then referencing is not necessary use ($data).