(PHP 5)

ReflectionClass::newInstanceنمونه جدید


public object ReflectionClass::newInstance ( mixed $args [, mixed $... ] )

نمونه جدید.


This function is currently not documented; only its argument list is available.



پذیرفتن تعداد متغیر آرگومان ارسالی به تابع مانند call_user_func().

Return Values

See Also

add a note add a note

User Contributed Notes 1 note

glen at delfi dot ee
2 years ago
looks like reflection class newInstance creates in memory representation of code where values are used, so using reference as constructor signature, you can not use this method.

as  the same input if called via new, or new $class works, but not via reflection:

class a {
     public function __construct(&$a, $c) {

// this works
$A = new stdClass();
$a = new a($A, 11);

// also this works
$classname = "a";
$a = new $classname($A, 10);

// but this fails:
$r = new ReflectionClass("a");
$r->newInstance($A, 10);

PHP Warning:  Parameter 1 to a::__construct() expected to be a reference, value given in reflection.php on line 15

PHP Warning:  ReflectionClass::newInstance(): Invocation of a's constructor failed in reflection.php on line 15
To Top