Given the following two functions, what statement is correct?
<code>
functiondynamicNew($name) {
returnnew $name;
}
functionreflectionNew($name) {
$r = new ReflectionClass($name);
return$r->newInstanceArgs();
}
</code>

A.
Both functions do the same
B.
dynamicNew() results in a parse error, reflectionNew() works
With php5.6, the script
newInstanceArgs();
}
var_dump(dynamicNew(“A”));
var_dump(reflectionNew(“A”));
?>
outputs:
object(A)#1 (1) {
[“n”]=>
int(10)
}
object(A)#2 (1) {
[“n”]=>
int(10)
}
so I’d say “Both functions do the same”, am I wrong?
0
0
With php5.6, the script
…
error_reporting(E_ALL);
class A
{
public $n = 10;
}
function dynamicNew($name) {
return new $name;
}
function reflectionNew($name) {
$r = new ReflectionClass($name);
return $r->newInstanceArgs();
}
var_dump(dynamicNew(“A”));
var_dump(reflectionNew(“A”));
…
outputs:
object(A)#1 (1) {
[“n”]=>
int(10)
}
object(A)#2 (1) {
[“n”]=>
int(10)
}
so I’d say “Both functions do the same”, am I wrong?
0
0