title: Valid use for global variable in WordPress
body: <p>I am aware of the general advice to avoid global variables. However, I have a use case that seems to be a valid reason to use a global variable. My questions are a) is my logic sound and b) if not, what alternative approach might be better?</p>
  <p>Here is an overview of my use case and how I would use a global variable.</p>
  <ul>
  <li>I have a class that, in its constructor, pulls in data from a number of WordPress tables (across these tables there are hundreds of rows)</li>
  <li>The source data from those tables is quite static in the sense that it changes very infrequently (weeks/months)</li>
  <li>I have a global instance of my class which pull in the data and runs some transformations and calculations, which are as members of the object stored and exposed, as needed, by the object as properties</li>
  <li>For the sake of illustration, let's assume these (one-off) calculations are reasonably complex, but once calculated they never change</li>
  <li>Many pages throughout my site need/expose this data</li>
  </ul>
  <p>My thinking here is that the data never changes but, especially for some of the properties I expose, it would be wasteful to go to the database each time (an example might to calculate the average for one of the columns in the result set). So I create a global variable, initialized it with the result set and calculated properties and then just access that variable from the various pages I need it.</p>
  <p>Is this a reasonable use of a global variable and, if not, what's a better approach?</p>
  <p>Thank you.</p>