Hi,

I want to create an instance of a class and construct it with different
params. The class name is a variable and the params change in each class. Is
there a way to pass params to the constructor of a class like you pass
params in the function call_user_func_array() ?


BTW, there's a solution for it using eval, but looking for a better cleaner
way...
With eval:

$cls="MyClass";
$construct_params=array(10,true);
$eval_str="return new $cls(";
    for ($i=0; $i<count($construct_params); $i++)
        $eval_str.="\$construct_params[$i],";
    $eval_str=substr($eval_str,-1).");";
$obj=eval($eval_str);

thanks in advance,
    Lorderon.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to