PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 3.8.9
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v3.8.9
4.9.2 4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 All 200 releases
betterdocs / includes / Dependencies / PhpParser / Node / Scalar / DNumber.php

DNumber.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 3.8.9, at includes/Dependencies/PhpParser/Node/Scalar/DNumber.php

65 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPDeveloper\BetterDocs\Dependencies\PhpParser\Node\Scalar;
4
5 use WPDeveloper\BetterDocs\Dependencies\PhpParser\Node\Scalar;
6
7 class DNumber extends Scalar
8 {
9 /** @var float Number value */
10 public $value;
11
12 /**
13 * Constructs a float number scalar node.
14 *
15 * @param float $value Value of the number
16 * @param array $attributes Additional attributes
17 */
18 public function __construct($value, array $attributes = array()) {
19 parent::__construct($attributes);
20 $this->value = $value;
21 }
22
23 public function getSubNodeNames() {
24 return array('value');
25 }
26
27 /**
28 * @internal
29 *
30 * Parses a DNUMBER token like PHP would.
31 *
32 * @param string $str A string number
33 *
34 * @return float The parsed number
35 */
36 public static function parse($str) {
37 // if string contains any of .eE just cast it to float
38 if (false !== strpbrk($str, '.eE')) {
39 return (float) $str;
40 }
41
42 // otherwise it's an integer notation that overflowed into a float
43 // if it starts with 0 it's one of the special integer notations
44 if ('0' === $str[0]) {
45 // hex
46 if ('x' === $str[1] || 'X' === $str[1]) {
47 return hexdec($str);
48 }
49
50 // bin
51 if ('b' === $str[1] || 'B' === $str[1]) {
52 return bindec($str);
53 }
54
55 // oct
56 // substr($str, 0, strcspn($str, '89')) cuts the string at the first invalid digit (8 or 9)
57 // so that only the digits before that are used
58 return octdec(substr($str, 0, strcspn($str, '89')));
59 }
60
61 // dec
62 return (float) $str;
63 }
64 }
65