Where to put arrays with constant value that will be accessed many times?
<p>I have some arrays storing the possible parameters for some 3D printer commands. I use this to check if the command is legal. I am confused about where I should put these arrays. These arrays will only be accessed in the formatcheck function, and the function will be called many times as there are <strong>thousands</strong> of commands to check. Should I put these in the formatcheck function as variables or at the beginning of the class the formatcheck function is in, as private static variables?</p>
<pre><code>public function checkFileGcodeFormat()
{
    $Ms = array(82, 83, 84, 104, 106, 107, 109, 140, 190);
    $Gs = array(0, 1, 20, 21, 28, 90, 91, 92);
    $Ts = array(0, 1);
    if (
      !(
        $this-&gt;hasM() 
        &amp;&amp; $this-&gt;hasNoXYZ() 
        &amp;&amp; in_array($this-&gt;M, $this-&gt;Ms)
      ) 
      ||
      (
        $this-&gt;hasG() 
        &amp;&amp; in_array($this-&gt;G, $this-&gt;Gs)
      ) 
      ||
      (
        $this-&gt;hasT() 
        &amp;&amp; $this-&gt;hasNoXYZ() 
        &amp;&amp; in_array($this-&gt;T, $this-&gt;Ts)
      ) 
    )
        return false;
    else
        return true;
}   
</code></pre>
<p>or:</p>
<pre><code>private static $Ms = array(82, 83, 84, 104, 106, 107, 109, 140, 190);
private static $Gs = array(0, 1, 20, 21, 28, 90, 91, 92);
private static $Ts = array(0, 1);
...
...
public function checkFileGcodeFormat()
{
    if (
      !(
        $this-&gt;hasM() 
        &amp;&amp; $this-&gt;hasNoXYZ() 
        &amp;&amp; in_array($this-&gt;M, $this-&gt;Ms)
      ) 
      ||
      (
        $this-&gt;hasG() 
        &amp;&amp; in_array($this-&gt;G, $this-&gt;Gs)
      ) 
      ||
      (
        $this-&gt;hasT() 
        &amp;&amp; $this-&gt;hasNoXYZ() 
        &amp;&amp; in_array($this-&gt;T, $this-&gt;Ts)
      ) 
    )
        return false;
    else
        return true;
}
</code></pre>