Two Best Solutions :
function create_instance($class, $params) {
return call_user_func_array(
array(new ReflectionClass($class), 'newInstance'),
$params
);
}
or
function create_instance($class, $params) {
$reflection_class = new ReflectionClass($class);
return $reflection_class->newInstanceArgs($params);
}
No comments:
Post a Comment