title: PHP dynamic require
body: <p>The main issue it's still the same:</p>
  
  <p>This is my proyect</p>
  
  <pre><code>/
  | index.php
  |-test1
     | test.php
  </code></pre>
  
  <p>The test.php</p>
  
  <pre><code>&lt;?php
  
  echo $variable;
  
  
  ?&gt;
  </code></pre>
  
  <p>The index.php</p>
  
  <pre><code>&lt;?php
  
  $variable = "&lt;br&gt;index";
  
  echo 'test&lt;br&gt;';
  
  $full_path = dirname(__FILE__)."/test1";
  $adm_extension = array( "php");
  
  if (is_dir($full_path)) {
      if (($handle = opendir($full_path))) {
          while ($file = readdir($handle)) {
              if (is_file($full_path . '/' . $file)) {
                  $item_path = $full_path . '/' . $file;
                  $extension = pathinfo($item_path, PATHINFO_EXTENSION);
                      if (in_array($extension, $adm_extension)) {
                          require $item_path;
                      }
              }
          }
      }
  }
  </code></pre>
  
  <p>And it's works like a charm, the output is:</p>
  
  <pre><code>test
  
  index
  </code></pre>
  
  <p>If i want to encapsulate this functionality in a function like this:</p>
  
  <p>index1.php</p>
  
  <pre><code>$variable = "&lt;br&gt;index";
  
  echo 'test&lt;br&gt;';
  
  $full_path = dirname(__FILE__)."/test1";
  $adm_extension = array( "php" );
  
  function rTest($full_path, $adm_extension){
  if (is_dir($full_path)) {
      if (($handle = opendir($full_path))) {
          while ($file = readdir($handle)) {
              if (is_file($full_path . '/' . $file)) {
                  $item_path = $full_path . '/' . $file;
                  $extension = pathinfo($item_path, PATHINFO_EXTENSION);
                      if (in_array($extension, $adm_extension)) {
                          require $item_path;
                      }
              }
          }
      }
  }
  }
  
  rTest($full_path, $adm_extension);
  </code></pre>
  
  <p>I got this:</p>
  
  <pre><code>( ! ) Notice: Undefined variable: variable in C:\wamp\www\sandbox\test1\test.php on line 3
  </code></pre>
  
  <p>Any clue??</p>