Question about eval in PHP 5

前端 未结 7 1277
误落风尘
误落风尘 2020-12-21 16:44

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

相关标签:
7条回答
  • 2020-12-21 17:22

    Well I have used eval once. This was for a system, where the users could enter formulas using constants fished from the underlying system.

    A string like:

    (N * (G - 2,7)) / E
    

    was taken and the constants replaced with values from the system eval is then used to get a value. eval seemed like the easiest way to go. The statement was filtered to only allow operators and uppercase letters(no two next to each other) so perhaps this is not a "real" use case of eval, but it works and is pretty readable.

    That said the system in questing is huge (200k+ lines) and this is the only place that eval is used.

    0 讨论(0)
提交回复
热议问题