title: Calling a PHP class from within another class
body: <p>really simple one I'm guessing but why does the below not work? I'm guessing it's a scope thing where class2 isn't visible from within class1. Yes, I'm getting "Call to member function on a non-object" error. </p>
  
  <pre><code>class class1 {
      function func1() {
          $class2-&gt;func3();
      }
      function func2() {
          $this-&gt;func1();
      }
  }
  
  class class2 {
      function func3() {
          echo "hello!";
      }
  }
  
  $class1 = new class1();
  $class2 = new class2();
  
  $class1-&gt;func1;
  </code></pre>
  
  <p>If anyone can give me a fix for this I'd be very grateful. I've been searching around for a while but I'm getting lots of examples of others trying to instantiate new classes inside other classes and similar and not this particular problem I have.</p>
  
  <p>You'd be right in thinking I don't do a whole lot with classes!</p>