This is an interesting question. If it wasn't a constructor function you were trying to give dynamic arguments to, then normally you could use call_user_func_array(). However, since the new operator is involved, there doesn't seem to be an elegant way to do this.
Reflection seems to be the consensus from what I could find. The following snippet is taken from the user comments on call_user_func_array(), and illustrates the usage quite nicely:
<?php // arguments you wish to pass to constructor of new object $args = array('a', 'b'); // class name of new object $className = 'myCommand'; // make a reflection object $reflectionObj = new ReflectionClass($className); // use Reflection to create a new instance, using the $args $command = $reflectionObj->newInstanceArgs($args); // this is the same as: new myCommand('a', 'b'); ?>
To shorten it up for your case, you can use:
$reflectionObject = new ReflectionClass($class); $obj = $reflectionObject->newInstanceArgs($key);