title: PHP my class loader that autoloads dependencies errors when there's more than one dependency
body: <p>I'm making my own framework and it has a function that creates classes. If classA has a property called classes than that means that classA requires whatever classes is in the classes property which is an array where key=className and value=classInstance.</p>
  
  <p>i.e if this class was loaded it would create foo and biz instances and replace null with them</p>
  
  <pre><code>class foo
  {
      public $classes=array('bar'=&gt;null, 'biz'=&gt;null);
  }
  </code></pre>
  
  <p>My framework works fine if there is only one dependency but when there is more, only the last one in the array loads successfully. and the rest are set to false =/ this is puzzling because it should set a message to a property with the error but it isnt...</p>
  
  <p>anyways here is the main class that handles the loading and errors
  the method that makes the classes is create().</p>
  
  <pre><code>&lt;?php
  session_start();
  class yamiko 
  {
      public $paths=array
              (
          'php'=&gt;'_php/',
          'js'=&gt;'_js/',
          'css'=&gt;'_style/',
          'template'=&gt;'_template/'
              );
      public $url=null;#defined in constructor
      public $classes=array();
      private $errors=array();
      private $warnings=array();
  
      /*
       * define $this-&gt;url
       * @RETURN: none
       */
      public function __construct() 
      {
          $this-&gt;url=urlencode($_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]);
      }
  
      ###################
      ##### CLASSES #####
      ###################
  
      /*
       * create a class instance
       * @RETURN OBJECT||false: returns reference to object of false if failed 
       * @PARAM $class STRING: path and class name.
       */
      public function &amp;create($class, $php=false, $c=0)
      {
          #check if php class
          if($php)
          {
              #make instance
              if(!$this-&gt;get_class($class))
              {
                  $this-&gt;classes[$class]=new $class;
              }
              return $this-&gt;classes[$class];
          }else#non php class
          {
              $path=$class;
              $pos=strrpos($path, '/');
              $class=substr($path, $pos+1);
              $path=substr($path, 0, $pos+1);
              if($this-&gt;get_class($class))
                  return $this-&gt;classes[$class];#return existing class
              if(file_exists($path.$class.'.php'))
              {
                  include_once($path.$class.'.php');
              }  else
              {
                  $this-&gt;set_error("unable to include $path$class");
                  return false;
              }
              $this-&gt;classes[$class]=new $class;
              #get required classes for class
              if(property_exists($this-&gt;classes[$class], 'classes'))#if class has a classes property
              {
                  foreach($this-&gt;classes[$class]-&gt;classes as $k=&gt;$v)
                  {
                      $required_class=$this-&gt;get_class($k);#check if it already exist
                      if(!$required_class)
                      {
                          $required_class=&amp;$this-&gt;create($path.$k, false, $c+1);
                          if(!$required_class)
                          {
                              $this-&gt;set_error("Class $class requires class $k");
                              return FALSE;
                          }
                      }
                      $this-&gt;classes[$class]-&gt;classes[$k]=&amp;$required_class;
                  }
              }
              return $this-&gt;classes[$class];
          }
      }
  
      /*
       * gets a references to a class or returns false
       * @RETURN OBJECT||false: returns reference to class or false if not found
       */
      public function &amp;get_class($class)
      {
          if($this-&gt;classes[$class] instanceof $class)
              return $this-&gt;classes[$class];
          $this-&gt;set_warn("$class does not exist");
          return false;
      }
  
      ###################
      ##### ERRORS ######
      ###################
  
      public function set_error($e)
      {
          $this-&gt;errors[]=$e;
      }
  
      public function get_error($r)
      {
          if(empty($this-&gt;errors))
              return false;
          switch ($r)
          {
              case 'html':
                  $html='&lt;ul&gt;';
                  foreach($this-&gt;errors as $k=&gt;$v)
                  {
                      $html.="&lt;li&gt;&lt;b&gt;ERROR $k:&lt;/b&gt; $v &lt;/li&gt;";
                  }
                  $html.='&lt;/ul&gt;';
                  return $html;
              break;
              default:#array
                  return $this-&gt;errors;
                  break;
          }
      }
  
      ####################
      ##### WARNINGS #####
      ####################
  
      public function set_warn($w)
      {
          $this-&gt;warnings[]=$w;
      }
  
      public function get_warn($r)
      {
          if(!empty($this-&gt;warnings))
              return false;
          switch ($r)
          {
              case 'html':
                  $html='&lt;ul&gt;';
                  foreach($this-&gt;warnings as $k=&gt;$v)
                  {
                      $html.="&lt;li&gt;&lt;b&gt;WARNING $k:&lt;/b&gt; $v &lt;/li&gt;";
                  }
                  $html.='&lt;/ul&gt;';
                  return $html;
              break;
              default:#array
                  return $this-&gt;warnings;
                  break;
          }
      }
  
      ################
      ##### DEBUG ####
      ################
  
      public function debug($msg, $r)
      {
          if(!is_string($msg))
          {
              $this-&gt;set_error('yamiko-&gt;debug msg is not a string');
              return false;
          }
          if($msg!='li'&amp;&amp;$msg!='br'&amp;&amp;$msg!='h1'&amp;&amp;$msg!='h2'&amp;&amp;$msg!='h3')
          {
              $this-&gt;set_error('yamiko-&gt;debug PARAM $r must be li, br, h1, h2, or h3');
              return false;
          }   
          switch($r)
          {
              case 'li':
                  echo "&lt;li&gt;$msg&lt;/li&gt;";
                  break;
              case 'br':
                  echo "$msg&lt;br /&gt;";
                  break;
              case 'h1':
                  echo "&lt;h1&gt;$msg&lt;/h1&gt;";
                  break;
              case 'h2':
                  echo "&lt;h2&gt;$msg&lt;/h2&gt;";
                  break;
              case 'h3':
                  echo "&lt;h3&gt;$msg&lt;/h3&gt;";
                  break;
          }
      }
  }
  global $yamiko;
  $yamiko=new yamiko;
  $GLOBALS['yamiko']=&amp;$yamiko;
  ?&gt;
  </code></pre>
  
  <p>and the class that im trying to load is set up like below and only the first class loads. ive switched the order and again only the first class loads.</p>
  
  <pre><code>&lt;?php
  class account
  {
      public $classes=array
      (
  'yamiko_mysqli'=&gt;NULL,
  'yamiko_encrypt'=&gt;NULL
      );
  }
  ?&gt;
  </code></pre>