首页 > 解决方案 > PHP 评估一个字符串作为一个类

问题描述

我正在检索一个字符串,我想将它称为一个新类

我试过: $class = eval("new $string()") 但它不起作用。

$class = eval("new {$string}()");

标签: php

解决方案


你不需要 eval 。

$class = new $string();

推荐阅读