note 87945 modified in language.oop5.autoload by lynch

From: Date: Thu, 03 Jun 2010 19:57:51 +0000
Subject: note 87945 modified in language.oop5.autoload by lynch
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-169869@lists.php.net to get a copy of this message
I found out a neat way to centralize one single class which will give accessibility to other classes. I also added a parameter to the __construct method which would be an array of classes you want loaded. This isn't completely necessary, but it will stop "excessive memory" if you're loading a bunch of unused classes. <?php class Bot { private $classes = array ( 'Socket' => "connection/class.Socket.php", 'Input' => "io/class.Input.php", 'Output' => "io/class.Output.php", 'Parse' => "io/parse/class.Parse.php" ); public $Socket, $Input, $Output, $Parse; // Accessible by other classes public function __construct($load=false){ if(is_array($load)){ foreach($load as $class){ if(isset($this->classes[$class])){ require($this->classes[$class]); $this->$class = new $class($this); } } } else { foreach($this->classes as $class => $path){ require($path); $this->$class = new $class($this); } } } } ?> --was-- I found out a neat way to centralize one single class which will give accessibility to other classes. I also added a parameter to the __construct method which would be an array of classes you want loaded. This isn't completely necessary, but it will stop "excessive memory" if you're loading a bunch of unused classes. <?php class Bot { private $classes = array ( 'Socket' => "connection/class.Socket.php", 'Input' => "io/class.Input.php", 'Output' => "io/class.Output.php", 'Parse' => "io/parse/class.Parse.php" ); public $Socket, $Input, $Output, $Parse; // Accessible by other classes public function __construct($load=false){ if(is_array($load)){ foreach($load as $class){ if(isset($this->classes[$class])){ require($this->classes[$class]); $this->$class = new $class($this); } } } else { foreach($this->classes as $class => $path){ require($path); $this->$class = new $class($this); } } } } ?> http://php.net/manual/en/language.oop5.autoload.php

« previous php.notes (#169869) next »