function Float_::parse
@internal
Parses a DNUMBER token like PHP would.
Parameters
string $str A string number:
Return value
float The parsed number
1 call to Float_::parse()
- Float_::fromString in vendor/
nikic/ php-parser/ lib/ PhpParser/ Node/ Scalar/ Float_.php
File
-
vendor/
nikic/ php-parser/ lib/ PhpParser/ Node/ Scalar/ Float_.php, line 45
Class
Namespace
PhpParser\Node\ScalarCode
public static function parse(string $str) : float {
$str = str_replace('_', '', $str);
// Check whether this is one of the special integer notations.
if ('0' === $str[0]) {
// hex
if ('x' === $str[1] || 'X' === $str[1]) {
return hexdec($str);
}
// bin
if ('b' === $str[1] || 'B' === $str[1]) {
return bindec($str);
}
// oct, but only if the string does not contain any of '.eE'.
if (false === strpbrk($str, '.eE')) {
// substr($str, 0, strcspn($str, '89')) cuts the string at the first invalid digit
// (8 or 9) so that only the digits before that are used.
return octdec(substr($str, 0, strcspn($str, '89')));
}
}
// dec
return (double) $str;
}