php - PHP 评估一个字符串作为一个类
问题描述
我正在检索一个字符串,我想将它称为一个新类
我试过: $class = eval("new $string()") 但它不起作用。
$class = eval("new {$string}()");
解决方案
你不需要 eval 。
$class = new $string();
推荐阅读
- r - R For 循环输出到表中
- metrics - 计算 librato 度量的点数
- c# - 如何在构造函数之外实例化?
- python - Python:在文件范围内循环
- java - 如何修复 HTTP 状态 500 - 内部服务器错误 | 小服务程序错误
- java - Android:主要项目所依赖的库中的 NFC 意图
- react-native - 反应原生 flatlist androidTV 焦点问题
- apache-spark - Spark 默认类
- python - 使用具有不同范围图的 mark_inset
- mongodb - 从 Python Eve 连接到访问受控的 MongoDB 副本集