'eval()评估'条件的替代方法 [英] Alternative for 'eval() uating' a condition

查看:78
本文介绍了'eval()评估'条件的替代方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我正在使用的旧版代码库中,有一个条件评估器,它接受用户输入以建立条件。然后在运行时使用php eval()评估此条件。在不使用评估的情况下解决此问题的最佳方法是什么。

In the legacy codebase that I am working on, there is a condition evaluator which accepts user input to build a condition. This condition is then evaluated at run-time using php eval(). What is the best way to resolve this without using eval.

例如我在用户界面中输入了条件 1> 0。必须对此进行评估,并返回结果(在这种情况下为true)。有什么建议吗?

For e.g. I have a condition "1>0" entered by the user in the UI. This has to evaluated and the result (true in this case) returned. Any suggestions?

让我们知道问题是否模糊,我会尽力加以解释。

Let know if the problem seems vague, I would try and explain better.

推荐答案

evalMath解析器在PHPClasses上提供了评估这种类型表达式的安全框架。

The evalMath parser over on PHPClasses provides a safe framework for evaluating this type of expression.

这篇关于'eval()评估'条件的替代方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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