how to get a class constructor function name without instantiating the class?
example:
$class = 'someClass';
$constructor = somehow get constructor;
$args = array();
$object = call_user_func_array(array($class,$constructor),$args);
what I need is to create a object by passing a undetermined number of variables into it’s constructor.
You can do this with Reflection:
This will also work if your constructor uses the old style (unless your code makes use of namespaces and you are using PHP 5.3.3 or, presumably, greater, as old-style constructors will no longer work with namespaced code – more info):
If the class has no constructor and you wish to use reflection, use
$class->newInstance()instead of$class->newInstanceArgs(...). To do this dynamically, it would look like this: