Reputation: 764
The following code successfully validates the string "0123.250" as a valid float, when it is not. Is this a PHP bug or did I do something wrong?
filter_var('0123.250', FILTER_VALIDATE_FLOAT);
Upvotes: 3
Views: 456
Reputation: 16905
From the PHP documentation on float literals:
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]+
.
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
.
Upvotes: 3
Reputation:
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.
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.
Upvotes: 1