Skip to content

Instantly share code, notes, and snippets.

@assertchris
Created December 4, 2012 08:37
Show Gist options
  • Select an option

  • Save assertchris/4201869 to your computer and use it in GitHub Desktop.

Select an option

Save assertchris/4201869 to your computer and use it in GitHub Desktop.
function create($name, $parameters = [])
{
$name = str_replace(".", "\\", $name);
$reflection = new ReflectionClass($name);
return $reflection->newInstanceArgs($parameters);
}
create("Some.Namespaced.Class", [$arg1, $arg2]); # -> new Some\Namespaced\Class($arg1, $arg2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment