I\'ve been looking into substantiating a new class instance from a string in PHP. This is seems to be an acceptable procedure, however I am curious why it can\'t be done with th
There are exactly four options of creating a class instance using new
that I know:
$bar = new Bar;
$barName = 'Bar'; $bar = new $barName;
$obj = (object) ['barName' => 'Bar']; $bar = new $obj->barName
;$bar1 = new Bar; $bar2 = new $bar1;
First half of an answer to your question is PHP parser: it prohibits many things like new (Foo)
and new "Foo"
that could used to build a hack.
Second half may hide in PHP sources: here's the C function that throws that exception.