Is it possible to do the following in one line? For instance, something like $obj=new "entry_{$type}";
Thanks
$class="entry_{$type}";
$obj=new $class();
Is it possible to do the following in one line? For instance, something like $obj=new "entry_{$type}";
Thanks
$class="entry_{$type}";
$obj=new $class();
Yes, but only if you really want it. It's a bit awkward:
$obj = new ${!${''}="entry_$type"}();
From: Code-Golf: one line PHP syntax
PHP wants to eventually move to a proper parser that uses an Abstract Syntax Tree, which might tighten up syntax holes that currently prevent, for example, new ("entry_$type")()
or something like that.