PHP的浮动错误:PHP挂起的数值 [英] PHP float bug: PHP Hangs On Numeric Value
问题描述
我刚刚读了一篇关于php挂在某些浮点数的有趣文章,参见注册和探索二进制
我从来没有明确地使用浮点数,我使用 number_format()
来清理我的输入并显示例如价格。
另外,据我所知,例如形式的所有输入都是字符串,直到我告诉他们,否则我认为这个问题不会影响我。
我是对的,还是我需要检查我的服务器上的Wordpress和Squirrelmail安装示例,看看他们是否投入任何浮动?或者更好, grep
我的服务器上的所有php文件都是 float
?
-ffloat-store
进行构建(会降低代码速度)。寻找具有 float
可能不会有帮助,因为引擎在许多字符串 - >数字转换场景中使用 zend_strtod
。
这个代码btw是标准的BSD库 strtod
代码,不是PHP独有的。所以使用这个代码的其他项目也可能会受到影响。
I just read an interesting article about php hanging on certain float numbers, see The Register and Exploring Binary.
I never explicitly use floats, I use number_format()
to clean my input and display for example prices.
Also, as far as I am aware, all input from for example forms are strings until I tell them otherwise so I am supposing that this problem does not affect me.
Am I right, or do I need to check for example Wordpress and Squirrelmail installations on my server to see if they cast anything to float? Or better, grep
all php files on my servers for float
?
Ways to mitigate the problem:
- Use a modern CPU. Most modern 64-bit CPUs would be immune (I actually had trouble finding host that allows to reproduce it since they tend to use more modern hardware). Amazon VMs seem to be immune too.
- Upgrade your PHP version - 5.3.5 and 5.2.17 once released (probably today) include the fix.
- Build with
-ffloat-store
in CFLAGS (will slow down the code). - Manually apply the patch to your code and rebuild PHP.
Looking for the code that has float
probably won't help as zend_strtod
is used by the engine in many string->number conversion scenarios.
P.S. this code btw is standard BSD library strtod
code, not unique to PHP. So other projects using this code might be affected too.
这篇关于PHP的浮动错误:PHP挂起的数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!