note 34176 added to function.class-exists
| From: | anonymous at rack1 dot php dot net | Date: | Thu, 17 Jul 2003 17:20:31 +0000 |
| Subject: | note 34176 added to function.class-exists | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-52287@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
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
----
Manual Page -- http://www.php.net/manual/en/function.class-exists.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34176
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34176&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34176&report=yes