vanderlee/expression
Composer 安装命令:
composer require vanderlee/expression
包简介
Safe, eval()-based simple and extendable expression parser
关键字:
README 文档
README
Version 1.0.3
Simple and fast PHP expression parser, based on secure use of eval().
Compatible with PHP 7.1 and up.
Using eval() is evil()
This class tries to expose a subset of PHP functionality not by removing the bad features, but by explicitly allowing only the good features.
IF YOU FIND ANY (POTENTIAL) SECURITY ISSUE, PLEASE REPORT!
Since PHP-Expression uses eval(), it can also handle PHP syntax, including
parenthesis, arithmetic, functions and more.
Things you are allowed to do
- Use numbers, either floating-point or integer, including negative.
- Use a number of different bases, such as decimal, octal, hexadecimal.
- Use most basic math functions such as
abs(),min(),max()andsqrt(). - Use basic arithmetic operators
+,-,*,/and%. - Use parenthesis.
- Use comparisons (
true/falsereturns1/0decimal). - Use boolean operators in comparisons.
- Use bitwise operators.
- Use textual boolean operators like
and,xorandor
Things we've added
- Binary numbers, using a
0bprefix. i.e.0b1001110. - New functions/function aliases.
- Support to use number "types" using prefixes.
- Boolean operator
^^for logical XOR (same asxor). - Textual boolean operator
not(same as!).
Things you should NOT be able to do
- Access functions not explicitly permitted.
- Access static classs method not explicitly permitted.
- Access class properties or functions.
- Access system constants.
- Access variables, local or global.
- Access Expression class itself.
- Access namespace functions.
- Access arrays of any kind, using either brackets or accolades.
- Use strings.
- Return anything except numbers (integer or floating-point, 1/0 for boolean results).
Things you cannnot do
- Ternary operator (
x ? y : z) not supported. - Elvis operator (
x ?: z) not supported. - Null-coalescing operator (
x ?? z) not supported. - Spaceship operator (
x <=> y) only supported on PHP 7 and up (it's a PHP 7 feature).
Available functions
TODO
Disclaimers
Though this class has been tested and independently reviewed by several people, I cannot make any absolute 100% guarantee that it cannot be hacked. If you find any potential security problem, please let us know.
Even though the Expression class itself is supposed to be secure, the return value may still be abused if your code does not check for validity. Only numbers can be returned, but if your code crashes on a number "666", the Expression class cannot and will not be able to protect you. Check for valid ranges.
vanderlee/expression 适用场景与选型建议
vanderlee/expression 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.97k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2017 年 04 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「parser」 「math」 「expression」 「eval」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 vanderlee/expression 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 vanderlee/expression 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 vanderlee/expression 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
LaTeX formula to PNG
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
Business rules engine tools.
An MT940 bank statement parser for PHP
Partition problem for balanced arrays splitting made easy.
Simple, chainable calculation library.
统计信息
- 总下载量: 10.97k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-04-04