As some others have said, there is nothing wrong with using globals; especially on a short script, it really can keep your code more readable than hiding it with an OO structure too large.
But you wrote: "I need [this variable] in a lot of functions, and Iβm kind of tired or using the global $ var_name, so much code
This suggests what you really want for all of these functions, using $ var_name for the class. As a refactory of the first stage, you pass the variable from another file to the constructor and replace all of your $var_name with $this->var_name , and then split all the lines global $var_name; .
You can get one global instance of this class, but that's fine. Globals are not evil, but they need to be controlled and documented as your code becomes more complex.
If you don't already have one, Martin Fowler's refactoring book reads well to help you deal when your 100-line script is now 1000 lines long and knocks you down. (Examples are in java, but are still available to the PHP programmer.)
Darren cook
source share