title: Static class variables in multiple php files
body: <p>I am pretty rusty on php, and am just learning how to use classes, and now something wierd is happening, which may just be how php works - I am not sure.</p>
  
  <p>I have an array which is static to a class (Project), and what I want to do is fill the array as soon as the page is loaded (in index.php), and then use projects from it from it when populating data. But I also want to use the SAME project array in other php files (such as my ajax_show_timesheet.php).</p>
  
  <p>When I try to access the array from another php file:</p>
  
  <pre><code>Project::$projectArray[key];
  </code></pre>
  
  <p>The array is empty. If I call </p>
  
  <pre><code>Project::createProjects();
  </code></pre>
  
  <p>again from within the other php file, it repopulates.</p>
  
  <p>So why can't I access the same static array from within various .php files?</p>
  
  <p>Here is what I am doing:</p>
  
  <p><strong>CLASS PROJECT:</strong></p>
  
  <pre><code>class Project
  {
  
    public static $projectArray;
  
    public $projectID;
  
    public function __construct($projID=0){
      $this-&gt;projectID = $projID;
  
    }
  
    public static function createProjects(){
  
      $projectResult = mysql_query("SELECT * FROM $tblProjects");
  
      $numRows = mysql_numrows($projectResult); 
      $i = 0;
  
      while($i &lt; $numRows){
        //for each project in the DB, add one to the array
        Project::$projectArray[mysql_result($projectResult, $i, "projectID")] 
               = new Project(mysql_result($projectResult, $i, "projectID"));
  
        $i++;
      }
    }
  }
  </code></pre>
  
  <p>In index.php I fill initialize Project:</p>
  
  <pre><code>Project::createProjects();
  </code></pre>
  
  <p>In ajax_show_timesheet.php I do something like:</p>
  
  <pre><code>echo Project::$projectArray[key]-&gt;projectID
  </code></pre>
  
  <p>and I just get back nothing.</p>
  
  <p>Any help on how to use static variables across multiple files would be great! </p>