Created
January 19, 2017 20:19
-
-
Save antonioribeiro/69759aec979d27d49beec21acbbdee86 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Instead of | |
$instance1 = app($class, $parameters); | |
// or | |
$instance2 = app()->make($class, $parameters); | |
// or | |
$instance3 = Container::getInstance()->make($class, $parameters); | |
// You may have to do something like | |
$instance4 = new $class($parameters[0]); | |
// but..., if you have more than one constructor argument, you may | |
$reflection = new ReflectionClass($class); | |
$instance5 = $reflection->newInstanceArgs($parameters); | |
// or you can just go Vanilla PHP and do | |
$instance6 = new YourClass($whatever, $parameter); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can also use the splat operator, which some might find more elegant than listing out multiple arguments without using the overhead of reflection.