array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'pt_BR', ), 'this' => array ( 0 => 'reflectionclass.newinstanceargs.php', 1 => 'ReflectionClass::newInstanceArgs', ), 'up' => array ( 0 => 'class.reflectionclass.php', 1 => 'ReflectionClass', ), 'prev' => array ( 0 => 'reflectionclass.newinstance.php', 1 => 'ReflectionClass::newInstance', ), 'next' => array ( 0 => 'reflectionclass.newinstancewithoutconstructor.php', 1 => 'ReflectionClass::newInstanceWithoutConstructor', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/reflection/reflectionclass/newinstanceargs.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5 >= 5.1.3, PHP 7, PHP 8)
ReflectionClass::newInstanceArgs — Creates a new class instance from given arguments
Creates a new instance of the class, the given arguments are passed to the class constructor.
Returns a new instance of the class, or null
on failure.
A ReflectionException if the class constructor is not public.
A ReflectionException if the class does not have a constructor
and the args
parameter contains one or more parameters.
Exemplo #1 Basic usage of ReflectionClass::newInstanceArgs()
<?php
$class = new ReflectionClass('ReflectionFunction');
$instance = $class->newInstanceArgs(array('substr'));
var_dump($instance);
?>
O exemplo acima produzirá:
object(ReflectionFunction)#2 (1) { ["name"]=> string(6) "substr" }