title: How to construct objects from files in a directory PHP
body: <p>I am writing a script to take care of my database migrations. I don't like using phinx, it doesn't allow for easy migrations for multiple databases.</p>
  
  <p>My migrations are in directory</p>
  
  <pre><code>migrations/
  </code></pre>
  
  <p>I have read this question, and used it.</p>
  
  <p><a href="https://stackoverflow.com/questions/4202175/php-script-to-loop-through-all-of-the-files-in-a-directory">PHP script to loop through all of the files in a directory?</a></p>
  
  <pre><code>foreach (glob("migrations/*.php") as $filename) {
      require_once $filename;
      $t = explode(".",$filename);
      $obj = strtolower($t[1]);
      $class = explode("/", $t[0]);
      ${$obj}= new $class[1]();     // make object from the class name
      ${$obj}-&gt;up();
  }
  </code></pre>
  
  <p>The file in migrations/ is Directory.php, it is a migration for the directory database, it has a method up() which I am trying to call. I want to run this script after provisioning, or manually via command line. It seems to be constructing the class ok. Getting the following error though...</p>
  
  <p>PHP Fatal error:  Call to undefined method Directory::up() </p>