I have a function that takes variadic arguments, that I obtain from func_get_args().
This function needs to call a constructor with those arguments. However, I don’t know how to do it.
With call_user_func, you can call functions with an array of arguments, but how would you call a constructor from it? I can’t just pass the array of arguments to it; it must believe I’ve called it “normally”.
Thank you!
For PHP < 5.3 it’s not easily doable without first creating an instance of the class with
call_user_func_array. However withReflectionthis is pretty trivial: