title: Fatal error: Uncaught exception 'RuntimeException'
body: <p>I'm running PHP version 5.2.11</p>
  
  <p>When I run the function below:</p>
  
  <pre><code>function get_dirs($path = '.') {
      $dirs = array();
      foreach (new DirectoryIterator($path) as $file) {  // This is line 462.
          if ($file-&gt;isDir() &amp;&amp; !$file-&gt;isDot()) {
              $dirs[] = $file-&gt;getFilename();
          }
      }
      return $dirs;
  }
  </code></pre>
  
  <p>I get this error: </p>
  
  <pre><code>Fatal error: Uncaught exception 'RuntimeException' with message 'DirectoryIterator::__construct(/home/test/test.com/wp-content/themes/mytheme/images) [&lt;a href='directoryiterator.--construct'&gt;directoryiterator.--construct&lt;/a&gt;]: failed to open dir: No such file or directory' in /home/test/test.com/testing123/wp-content/themes/mytheme/functions.php:462 Stack trace: #0 /home/test/test.com/testing123/wp-content/themes/mytheme/functions.php(462): DirectoryIterator-&gt;__construct('/home/test/wie...') #1 /home/test/test.com/testing123/wp-content/themes/mytheme/functions.php(31): get_dirs('/home/test/wie...') #2 /home/test/test.com/testing123/wp-settings.php(717): include('/home/test/wie...') #3 /home/test/test.com/testing123/wp-config.php(76): require_once('/home/test/wie...') #4 /home/test/test.com/testing123/wp-load.php(30): require_once('/home/test/wie...') #5 /home/test/test.com/testing123 in /home/test/test.com/testing123/wp-content/themes/mytheme/functions.php on line 462
  </code></pre>
  
  <p>UPDATE: The problem here I've found is that the theme was installed under a virtual directory off the main URL. My scripts are expecting that the theme is installed off the main root url.</p>
  
  <p>For example, the theme in this case was installed at: <a href="http://www.example.com/testing123/wp-content/themes/mytheme" rel="nofollow noreferrer">http://www.example.com/testing123/wp-content/themes/mytheme</a></p>
  
  <p>However, I'm expecting this: <a href="http://www.example.com/wp-content/themes/mytheme" rel="nofollow noreferrer">http://www.example.com/wp-content/themes/mytheme</a></p>
  
  <p>AND SO...</p>
  
  <p>My path function fails since it does not take into consideration that it could be installed under a virtual directory.</p>
  
  <p>How could I account for this scenario in my feeding of this function?</p>
  
  <pre><code>$mydir = get_dirs("$_SERVER[DOCUMENT_ROOT]/wp-content/themes/mytheme/images");
  
  function get_dirs ($path = '.') {
      $dirs = array();
      foreach (new DirectoryIterator($path) as $file) {
          if ($file-&gt;isDir() &amp;&amp; !$file-&gt;isDot()) {
              $dirs[] = $file-&gt;getFilename();
          }
      }
  
      return $dirs;
  }
  </code></pre>