首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在php中,eval什么时候是邪恶的?

在php中,eval什么时候是邪恶的?
EN

Stack Overflow用户
提问于 2009-06-04 15:43:27
回答 11查看 45.5K关注 0票数 88

在我用PHP开发的这么多年里,我总是听说使用eval()是邪恶的。

考虑到下面的代码,使用第二个(也是更优雅的)选项不是很有意义吗?若否,原因为何?

// $type is the result of an SQL statement, e.g.
// SHOW COLUMNS FROM a_table LIKE 'a_column';
// hence you can be pretty sure about the consistency
// of your string.

$type = "enum('a','b','c')";

// option one
$type_1 = preg_replace('#^enum\s*\(\s*\'|\'\s*\)\s*$#', '', $type);
$result = preg_split('#\'\s*,\s*\'#', $type_1);

// option two
eval('$result = '.preg_replace('#^enum#','array', $type).';');
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/951373

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档