note 41822 deleted from function.func-get-args by bjori
| From: | bjori@php.net | Date: | Tue, 25 Apr 2006 19:11:18 +0000 |
| Subject: | note 41822 deleted from function.func-get-args by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-109676@lists.php.net to get a copy of this message | ||
Note Submitter: flobee at gmx dot net
----
re.: avenger at php (#) net #s post ->
here is a litte tool to load/get objects on request (saves a lot of power and inclusions requests)
(seems that the __autoload of php5 will do this)
<?php
function &LoadClass($instance) {
static $loadedClasses = NULL;
$numargs = func_num_args();
if( $numargs > 1 ) {
$arg_list = func_get_args();
for($i=1;$i<$numargs;$i++) {
if($i+1 == $numargs) {
$args .= $arg_list[$i];
} else {
$args .= $arg_list[$i] .', ';
}
}
}
if( !class_exists( $instance ) ) {
if( $err = include_once('./lib/class.'. $instance .'.php') ) {
define("_CLASS_".strtoupper($instance),TRUE);
$loadedClasses[$instance] = new $instance($args);
} else {
exit('Error! could not include: ./lib/class.'.$instance.'.php'.
$err);
}
} else {
$loadedClasses[$instance] = new $instance($args);
}
return $loadedClasses[$instance];
}
// test:
// include class.MyTest.php
$myObject = & LoadClass('MyTest', $var1='hello',$var2='php');
?>