title: php memory error in depenency injection
body: <p>I would have used google but I'm going out and hope u guys can help me with a solution or tell me what I'm doing wrong by the time I get back.</p>
  
  <p>I passed in an instance of my factory to my controller and based on something I want to use the factory to begin another instance of a controller that is related to this one bit I get</p>
  
  <pre><code> Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 24 bytes) in C:\xampp\htdocs\includes\object_factory_inc.php on line 19
  </code></pre>
  
  <p>I'm here is the factory and the controller I'm trying to call it from</p>
  
  <p><strong>factory</strong> </p>
  
  <pre><code>/* The purpose of this class is to create the instance of a class when needed and how needed.
          For example we could have created the controller object inline but in recognition
          of the polymorphic behavior of controllers we have the decided to create it in our object-
          factory class(this class) which serves to hide the logic of creating the correct instance of
          a specified controller. 
  
          For example the 'build_index_controller' function uses the second parameter
          of the parameters passed to it to decide on the instance of the index to call
          */
  
  
  class object_factory_inc
  {
      public function build_controller($controller_name,array $controller_params)
      {
          $indexed_controller_params=array_values($controller_params);
          $controller_name=strtolower($controller_name);
  
  
          if(!isset($indexed_controller_params[0]))
          {
  
              $controller_name=$controller_name."_controller";
              return new $controller_name($this,$controller_params);
  
          }
  
          else
          {
              $controller_build_function="build_".$controller_name."_controller";
              method_exists($this,$controller_build_function)?$this-&gt;$controller_build_function($controller_name,$controller_params,$indexed_controller_params):$this-&gt;controller_doesn't_exist($controller_build_function);
                  }
  
              }
  
              private function build_index_controller($controller_name,array $controller_params,array $indexed_controller_params)
              {
                  strtolower($indexed_controller_params[0]);
                  switch ($indexed_controller_params[0])
                  {
                      case "s":
                      $controller_name=$controller_name."_search_controller";
                      return new $controller_name($this,$controller_params);
                      break;
  
                      case "admin":
                      $controller_name=$controller_name."_admin_controller";
                      return new $controller_name($this,$controller_params);
                      break;
  
                      case "loggedin":
                      $controller_name=$controller_name."_loggedin_controller";
                      return new $controller_name($this,$controller_params);
                      break;
  
                      default://if it doesn't exist just run default controller behaviour consider running 404
              $controller_name=$controller_name."_controller";
              return $controller_name($this,$controller_params);
          }
  
      }
  
  
      private function controller_doesnt_exist($controller_name)
      {
          echo "404 error ".$controller_name." doesn't exist on this server";
      }
  }
  </code></pre>
  
  <p>The controller I'm trying to run it from:</p>
  
  <pre><code>     class index_controller
      {
  
      protected $parameters=array();
      protected $default_operation='view';
      protected $object_factory;
  
      public function __construct(object_factory_inc $factory,array $parameters )
       {
          $this-&gt;object_factory=$factory;
          $this-&gt;parameters=$parameters;
          $this-&gt;varify_controller();
          //print_r($parameters);
          //var_dump($factory);
          //require_once "views/index_view.php";
  
  
        }
  
        private function varify_controller()
        {
            if(true)//if logged in session is set;
            {
                $indexd_parameteres=array_values($this-&gt;parameters);
                $indexd_parameteres[0]='loggedin';
                $this-&gt;object_factory-&gt;build_controller("index",$this-&gt;parameters);
            }
        }
  
      }
  
  the normal way the controllers are usually called are from the index here it is
  
      require_once 'includes/config.php';
  
  
          $route=isset($_GET['action'])?new router_controller($_GET['action']):new router_controller($_GET['action']="/index");
          $route-&gt;parse_route();
          $object_factory=new object_factory_inc;
          $controller=$object_factory-&gt;build_controller($route-&gt;get_controller(),$route-&gt;get_request_data());
  </code></pre>
  
  <p>sorry about the long question just wanted I gave you all you needed thanks in advance also if I'm doing something totally wrong please if you're gonna direct me to google at least give me something to google.</p>