note 41822 added to function.func-get-args
| From: | flobee at gmx dot net | Date: | Fri, 23 Apr 2004 02:53:02 +0000 |
| Subject: | note 41822 added to function.func-get-args | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-68566@lists.php.net to get a copy of this message | ||
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');
?>
----
Manual Page -- http://www.php.net/manual/en/function.func-get-args.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+41822
Delete -- http://master.php.net/manage/user-notes.php?action=delete+41822&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+41822&report=yes
Search -- http://master.php.net/manage/user-notes.php