How can I create a class with a given array of arguments to be sent to the constructor? Something along the lines of:
class a {
var $args = false;
function a() {$this->args = func_get_args();}
}
$a = call_user_func_array('new a',array(1,2,3));
print_r($a->args);
Ideally this needs to work, without modification to the class, in both PHP4 and PHP5. Any ideas?
ReflectionClass:newInstance() (or newInstanceArgs()) let’s you do that.
e.g.
edit: without ReflectionClass and probably php4 compatible (sorry, no php4 at hand right now)
speed comparison:
Since the speed of reflection has been mentioned here’s a little (synthetic) test
which prints on my (not so fast) notebook
Isn’t that bad, is it?