In the application I am creating, I need to pass an unknown number of parameters to an unknown class constructor. The class (+ namespace) is the string that is in $ class. Parameters are in an array.
This application will be deployed for a couple of months, so we thought that we could develop it already in PHP 5.6. So I thought the solution to this would be:
$instance = new $class(...$args);
It works...
But my colleagues do not want to accept this, because the CI server does not understand this line of code. Their solution will likely be:
$reflect = new \ReflectionClass($class);
$instance = $reflect->newInstanceArgs($args)
Now: both work fine, so no problem. But my thought is that Reflection is slower than other methods (like PHP 5.6).
Also a question: is it a good reflection, should I use the splat operator from the moment the CI server understands this line?
source
share