@@ -45,13 +45,7 @@ public static function fromString(string $str, array $attributes = []): Float_ {
45
45
public static function parse (string $ str ): float {
46
46
$ str = str_replace ('_ ' , '' , $ str );
47
47
48
- // if string contains any of .eE just cast it to float
49
- if (false !== strpbrk ($ str , '.eE ' )) {
50
- return (float ) $ str ;
51
- }
52
-
53
- // otherwise it's an integer notation that overflowed into a float
54
- // if it starts with 0 it's one of the special integer notations
48
+ // Check whether this is one of the special integer notations.
55
49
if ('0 ' === $ str [0 ]) {
56
50
// hex
57
51
if ('x ' === $ str [1 ] || 'X ' === $ str [1 ]) {
@@ -63,10 +57,12 @@ public static function parse(string $str): float {
63
57
return bindec ($ str );
64
58
}
65
59
66
- // oct
67
- // substr($str, 0, strcspn($str, '89')) cuts the string at the first invalid digit (8 or 9)
68
- // so that only the digits before that are used
69
- return octdec (substr ($ str , 0 , strcspn ($ str , '89 ' )));
60
+ // oct, but only if the string does not contain any of '.eE'.
61
+ if (false === strpbrk ($ str , '.eE ' )) {
62
+ // substr($str, 0, strcspn($str, '89')) cuts the string at the first invalid digit
63
+ // (8 or 9) so that only the digits before that are used.
64
+ return octdec (substr ($ str , 0 , strcspn ($ str , '89 ' )));
65
+ }
70
66
}
71
67
72
68
// dec
0 commit comments