dynamic object instances
| From: | Thomas Angst | Date: | Wed, 10 Aug 2005 16:51:18 +0000 |
| Subject: | dynamic object instances | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-220349@lists.php.net to get a copy of this message | ||
Hello List,
I would like to create an object inside a function with its classname and a parameter list submitted by the function call.
function create($class, $parameter) {
$obj = new $class($parameter);
return $obj;
}
This is working very well. But I have not every time the same count of parameters for a class constructor.
If this is a normal method call of an object I can realise it like this:
$ret = call_user_func_array(array(&$obj, 'method'), $parameter_array);
The $parameter_array contains as many entries as the function needs. Works well too.
But how can I write a function to instance objects with various count of parameters in the constructor?
I know, can do this with an eval. But I would like to find a solution where I don't need an eval.
thanks for all answers,
Thomas