note 87945 added to language.oop5.autoload

From: Date: Thu, 01 Jan 2009 00:55:30 +0000
Subject: note 87945 added to language.oop5.autoload
Groups: php.notes 
Request: Send a blank email to php-notes+get-148736@lists.php.net to get a copy of this message
I was noted of excessive memory usage for my last note, so a good workaround would be to add 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); } } } } ?> ---- Server IP: 64.71.164.2 Probable Submitter: 76.103.145.92 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.autoload.php Edit -- https://master.php.net/note/edit/87945 Del: integrated -- https://master.php.net/note/delete/87945/integrated Del: useless -- https://master.php.net/note/delete/87945/useless Del: bad code -- https://master.php.net/note/delete/87945/bad+code Del: spam -- https://master.php.net/note/delete/87945/spam Del: non-english -- https://master.php.net/note/delete/87945/non-english Del: in docs -- https://master.php.net/note/delete/87945/in+docs Del: other reasons-- https://master.php.net/note/delete/87945 Reject -- https://master.php.net/note/reject/87945 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#148736) next »