简体   繁体   English

PHP filter_var错误?

[英]PHP filter_var bug?

The following code successfully validates the string "0123.250" as a valid float, when it is not. 以下代码成功地将字符串“0123.250”验证为有效的浮点数,而不是。 Is this a PHP bug or did I do something wrong? 这是一个PHP错误还是我做错了什么?

filter_var('0123.250', FILTER_VALIDATE_FLOAT);

From the PHP documentation on float literals : 浮点文字PHP文档

LNUM          [0-9]+
DNUM          ([0-9]*[\.]{LNUM}) | ({LNUM}[\.][0-9]*)
EXPONENT_DNUM [+-]?(({LNUM} | {DNUM}) [eE][+-]? {LNUM})

As you can see, there is no restriction for leading zeroes, as indicated by these bits: [0-9]*[\\.] and [0-9]+ . 正如您所看到的,对于前导零没有限制,如这些位所示: [0-9]*[\\.][0-9]+

Since the page never once mentions octal, we need to assume that leading zeroes make no difference in the interpretation. 由于页面从未提及八进制,我们需要假设前导零在解释中没有区别。

I assume that the exact same rules are applied for FILTER_VALIDATE_FLOAT . 假设FILTER_VALIDATE_FLOAT应用完全相同的规则。

The leading 0 just makes explicit the fact that place value for thousands is zero, which is usually implied by the absence of a digit for that place value. 前导0只是明确了千位的值为零的事实,这通常是由于缺少该位值的数字而暗示的。

If you're worrying about the fact that the leading zero is a non significant digit, I don't think PHP follows the definition that closely. 如果你担心前导零是一个非重要数字的事实,我不认为PHP遵循这个定义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM