Code: Select all
function loadClass($name)
{
$args = func_get_args();
$args = "'".implode("', '", array_slice($args, 1))."'";
$newClass = new $name($args);
return $newClass;
}Code: Select all
$newObject = $existingClass->loadClass('className', 'arg1', 'arg2');the code above fails because it just takes all of the arguments (minus the 1st, which is the name of the class to be dynamically instantiated) and puts them into one string, which is passed as one argument.
i've also tried slicing off the first element of my arguments array and passing the array, but that just loads an array into my first argument.
so, without rewriting all of my classes to accept arrays instead of lists, is there a way to accept a number of arguments that is unknown beforehand and pass them on to a second function/class?
thanks for any insight you may have...
feyd | Please use
Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]