There are many reasons not to use global variables. Here are just a few:
- Region
- On a large system, it can be easy to accidentally reassign global variables if you reuse a semi-common name
- Variables on a global scale increase the memory capacity of your scripts. Not always important, but may be
- - - ,
, , - , .
classB::func($obj)
{
echo $obj->whatever();
}
$obj = new classAObject;
classB::func($obj);