As for me, i avoid using global, but i stumbled about a point, there the use seems to be the best solution. I build this function:
function _get($parameter_name)
{
global $argv; // register the argv array as a global variable
if (isset($argv))
{
parse_str(implode('&', array_slice($argv, 1)), $_GET);
}
return $_GET[$parameter_name];
}
The purpose of this method is to call _get('test') and fetch the value of an argument passed by argv or otherwise an url GET parameter. But i'm not sure about it.
I'm already aware, that the usage of global is bad pratice like mentioned in Are global variables in PHP considered bad practice? If so, why?. But the argv array is a little special. It's automatically filled through the php-cli and only accessible from the called script. If i want to access this variable from within a class method or a function, i need to pass it where, or put it in a public static class member. That would be a solution, but i don't want to write the same lines in every script to pass the array through many functions. That is not really nice. So i'm thinking about this way as another possible solution.
Your opinions about this or maybe a better way i'm not seeing at the moment?