note 47239 deleted from function.func-get-args by bjori
| From: | bjori@php.net | Date: | Tue, 25 Apr 2006 19:09:36 +0000 |
| Subject: | note 47239 deleted from function.func-get-args by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-109672@lists.php.net to get a copy of this message | ||
Note Submitter: intuz ät gmx döt de
----
An updated LoadClass / LoadModule function.
This function can be called with all PHP Values e.g. Arrays or Objects.
<?php
class SimpleClassLoader {
var $Module;
SimpleClassLoader() {
$this->Module = NULL;
}
function &LoadModule($incpath="inc/",$prefix="",$instance) {
if(!isset($this->Module[$instance])) {
$numargs = func_num_args();
if( $numargs > 3 ) {
$arg_list = func_get_args();
for($i=3;$i<count($arg_list);$i++) {
$parameter .= "\$arg_list[$i]";
if($i != (count($arg_list)-1)) $parameter .= ",";
}
// echo "Parameter: $parameter";
// eval("echo $parameter;");
}
if( !class_exists( $instance ) ) {
if( $err = include_once($incpath.$prefix.'class.'.$instance.'.php') ) {
define("_CLASS_".strtoupper($instance),TRUE);
eval("\$this->Module[\$instance] = new \$instance($parameter);");
} else {
exit('Error! could not include:
'.$incpath.$prefix.'class.'.$instance.'.php'.$err);
}
} else {
eval("\$this->Module[\$instance] = new \$instance($parameter);");
}
}
return $this->Module[$instance];
}
}
$MyObj = new SimpleClassLoader();
$MyObj->LoadModule("classes/","","MySql","localhost","...");
?>
Hope my Source is correct..
Hope it helps somebody.. :)