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