Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否可以在一行中执行以下操作?例如,像$obj=new "entry_{$type}"; 谢谢
$obj=new "entry_{$type}";
$class="entry_{$type}"; $obj=new $class();
是的,但前提是你真的想要它。有点尴尬:
$obj = new ${!${''}="entry_$type"}();
来自:Code-Golf:一行 PHP 语法
PHP 希望最终转移到使用抽象语法树的适当解析器,这可能会收紧当前阻止的语法漏洞,例如,new ("entry_$type")()或类似的东西。
new ("entry_$type")()