title: How can I initiate a PHP class and use it in several files?
body: <p>I am stumped right now.  In my last post about this question the answer was to use a singleton to make sure an object is only initiated 1 time but I am having the opposite problem.</p>
  
  <p>If I have a file called <strong>index.php</strong> and then I include these files into it, <strong>class1.php</strong>, <strong>class2.php</strong>, <strong>class3.php</strong>, <strong>class4.php</strong>.  </p>
  
  <p>In <strong>index.php</strong> I will have, </p>
  
  <pre><code>&lt;?PHP
  $session = new Session();  
  
  require_once '/includes/class1php';
  require_once '/includes/class2.php';
  require_once '/includes/class3.php';
  require_once '/includes/class4.php';
  ?&gt;
  </code></pre>
  
  <p>then in all 4 of the test files I will try to access a method called <strong>get()</strong> from the <strong>session class</strong>, assume the session class file is already included into the index.php page as well.  </p>
  
  <p>Now if I try to use...</p>
  
  <pre><code>$testvar = $session-&gt;get($var1);
  </code></pre>
  
  <p>in any of the test class files I will get this error  </p>
  
  <pre><code>Fatal error: Call to a member function get() on a non-object
  </code></pre>
  
  <p>the only way the code works without an error is if I use </p>
  
  <pre><code>$session = new Session(); 
  </code></pre>
  
  <p>in every file.  </p>
  
  <p><strong>How can I fix/avoid having to initaite the class in every file when it is already initated in the index.php file?</strong></p>
  
  <p>the goal is to let me initiate a class in 1 file like index.php and then include the class files into that page, the catch is most of the classes use methods from other classes so would be nice if I didn't have to initiate every class in every file</p>