关于PHP 5中的eval的问题 [英] Question about eval in PHP 5

查看:59
本文介绍了关于PHP 5中的eval的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从事PHP的工作已经快一年了,尽管我知道它的用法,但从未使用过eval()函数. 但是我在SO中发现了很多问题,所以有人可以给我展示一个简单的例子,其中有必要使用eval()吗?这是好事还是坏事?

I have been doing PHP stuff for almost one year and I have never used the function eval() though I know the usage of it. But I found many questions about it in SO.So can someone show me a simple example in which it's necessary to use eval()?And is it a good or bad practice?

推荐答案

使用eval()是一种不好的做法,如果发现有必要实现某些目标,则通常是潜在的设计错误的征兆.

Using eval() is a bad practice, and if it turns out to be necessary to achieve something, that is usually the sign of a underlying design error.

我想不出需要使用eval()的任何情况. (即,使用其他语言构造或修复损坏的设计无法实现某些目的.)感兴趣的是看看这里是否有任何真正的案例需要评估,或者实际上替代方案非常复杂.

I can't think of any situation where it is necessary to use eval(). (i.e. something can't be achieved using other language constructs, or by fixing a broken design.) Interested to see whether any genuine cases come up here where eval actually is necessary or the alternative would be horribly complex.

可能唯一需要执行的是执行来自外部源(例如数据库记录)的代码.但这是IMO本身的设计错误.

The only instance of where it could be necessary is for executing code coming from an external source (e.g. database records.) But this is a design error in itself IMO.

这篇关于关于PHP 5中的eval的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆