So I have a PHPUnit test, and found this code within a function.
global $argv, $argc;
echo $argc;
print_r($argv);
I understand what these variables represent (arguments passed from the command line), but I’ve never seen this syntax before:global $argv, $argc;
What specifically is going on here?
The
globalkeyword tells PHP to use the global scope version of a variable and make it visible to the current scope as well, so that variables declared outside functions/classes can be accessed within them too.Otherwise, trying to read/assign those variables would operate on a different local version of them instead.
Compare:
versus…