title: loading only needed files or all the framework?
body: <p>I have looked around stackoverflow and i still can't find an answer to my question.</p>
  
  <p>I am using my custom framework for a website and as of right now, i use an include in my index that php to load all the classes the framework uses. </p>
  
  <p>But for my database objects i use a little script to include all the files, because there are many layers of class for each table. (each table has at least 4 files)</p>
  
  <p>Here is the snippet i currently use to load them.</p>
  
  <pre><code>// the constants are the directories to look for files
  $__dirs = array(CORE_PATH,CX_SETTINGS,BASE_MODEL,MODEL,CUSTOM_MODEL,CONTROLLER,PLUG_IN,HELPER_FUNCTIONS);
  $__accepted_ext = '.php';
  foreach ($__dirs as $dir) {
      if ($handle = opendir($dir)) {
          // peer files first
          while (false !== ($file = readdir($handle))) {
              if ((strpos($file,$__accepted_ext) !== false)){
                  require_once($dir.DS.$file);
                  //echo "$dir : $file : works \n"; // debug
              }
          }
          closedir($handle);
      }
  }
  </code></pre>
  
  <p>This method will scan every directory i provide and include all my php files.</p>
  
  <p>My problem is that this load every single file of my framework, regardless i use them or not. So i assume this is not the best way to handle it, and that i might be creating unnecessary overhead. </p>
  
  <p>Now I read about the __autoload() function and i consider it my alternative. But is this something i should even be worried about (including even files i won't use)? What are the methods currently being used to handle this problem? </p>
  
  <p>EDIT:</p>
  
  <p><strong>NOTE:</strong> all the files included are classes, not files included by mistake.
  example: I might load the comment class, which is valid, but not used in all my pages. so it's in some way unnecessary </p>