title: Alternative to global variables in PHP
body: <p>Due to slowness, ( and also for coding reasons ), I know that the use of global variables should be avoided as much as possible. It's twice as slow and it decreases the understanding &amp; tracking of the code flow. But sometimes, you do need them in your functions. Sometimes, they do get very handy. </p>
  
  <p>To some degree constants can be used. But as the name says it all, they are constants after all and therefore, they cannot totally substitute the use of global variables. </p>
  
  <p>If you were to not use global variables, and you do need to use them due to the functionality they offer, what options would you refer to? What utilities are out there in PHP so that a variable can be tapped into within functions, outside of functions, basically anywhere and everywhere. Set it somewhere and read/modify it somewhere else.  </p>
  
  <p>As an example, I can throw in the use of session variables as an alternative.</p>
  
  <p>You may find it weird but a session variable can easily do the trick. It actually does the job better than a global variable; I can initialize my session variable right within my functions and in no time, all other parts of my code is able to work with that session variable. Whereas with the global variables, they must be introduced/defined outside the functions scope ( to be exact, at the top of the page ) before they may get used by other sections. Sessions won't suffer from this limitation. However, it is obvious, that Sessions are not the right tool for the goal at hand.  </p>
  
  <p>The question  is what other ways are out there to tackle the matter of "setting a variable somewhere and read/modify it anywhere else"?  </p>