note 34176 modified in function.class-exists by vrana

From: Date: Tue, 17 Aug 2004 14:54:59 +0000
Subject: note 34176 modified in function.class-exists by vrana
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-79941@lists.php.net to get a copy of this message
If you have a directory of classes you want to create. (Modules in my instance)... you can do it like that <?php if (is_dir($this->MODULE_PATH) && $dh = opendir($this->MODULE_PATH)) { while (($file = readdir($dh)) !== false) { if (preg_match("/(Mod[a-zA-Z0-9]+).php/", $file, $matches)>0) { // include and create the class require_once($this->MODULE_PATH."/".$file); $modules[] = new $matches[1](); } } } else { exit; } ?> //--- Here the rule is that all modules are on the form ModModulename.php and that the class has the same name as the file. The $modules array has all the classes initialized after this code --was-- If you have a directory of classes you want to create. (Modules in my instance)... you can do it like that if (is_dir($this->MODULE_PATH) && $dh = opendir($this->MODULE_PATH)) { while (($file = readdir($dh)) !== false) { if (preg_match("/(Mod[a-zA-Z0-9]+).php/", $file, $matches)>0) { // include and create the class require_once($this->MODULE_PATH."/".$file); $modules[] = new $matches[1](); } } } else { exit; } //--- Here the rule is that all modules are on the form ModModulename.php and that the class has the same name as the file. The $modules array has all the classes initialized after this code http://php.net/manual/en/function.class-exists.php

« previous php.notes (#79941) next »