是否可以在一行中执行以下操作?例如,像$obj=new "entry_{$type}";
谢谢
$class="entry_{$type}";
$obj=new $class();
答案 0 :(得分:4)
是的,但只有你真的想要它。这有点尴尬:
$obj = new ${!${''}="entry_$type"}();
来自:Code-Golf: one line PHP syntax
PHP希望最终move to a proper parser使用抽象语法树,这可能会加剧目前阻止的语法漏洞,例如new ("entry_$type")()
或类似的东西。