title: What's wrong with this PHP code snippet I found? I get undefined variable 'obj'
body: <p>I would like just to like to ask for a little elucidation about this three code snippets I found and how PHP behaves with them:</p>
  
  <p>1) a php class (tmp.class.php) with a static method call:</p>
  
  <pre><code>&lt;?php
  
  class Dummy {
          public function sayHello()
          {
              echo "HELLO FROM DUMMY";
          }
  
          public static function requireScript() {
              require __DIR__ . "/tmp2.php";
          }
  }
  
  Dummy::requireScript();
  </code></pre>
  
  <p>2) another file (tmp1.php), instantiating the previous defined class:</p>
  
  <pre><code>&lt;?php
  require_once __DIR__. "/tmp.class.php";
  
  $obj = new Dummy;
  
  ?&gt;
  </code></pre>
  
  <p>3) another file (tmp2.php), using the previous instance of the class:</p>
  
  <pre><code>&lt;?php
  
  require_once __DIR__ ."/tmp1.php";
  
  $obj-&gt;sayHello();
  
  ?&gt;
  </code></pre>
  
  <p>Now I know that as the requireScript() method has a require call in it, in fact the tmp2.php is included twice, am I right? But when I make the script run (open the tmp2.php file in the browser) I get a <strong>Notice: Undefined variable: obj</strong> and then of course a Fatal error because of the sayHello(); </p>
  
  <p>Shouldn't the $obj be available to the second required tmp2.php script? What is wrong with this code? </p>
  
  <p>Thanks for attention!</p>