Chris@13: value = $value; Chris@0: } Chris@0: Chris@13: public function getSubNodeNames() : array { Chris@13: return ['value']; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Constructs an LNumber node from a string number literal. Chris@0: * Chris@0: * @param string $str String number literal (decimal, octal, hex or binary) Chris@0: * @param array $attributes Additional attributes Chris@0: * @param bool $allowInvalidOctal Whether to allow invalid octal numbers (PHP 5) Chris@0: * Chris@0: * @return LNumber The constructed LNumber, including kind attribute Chris@0: */ Chris@13: public static function fromString(string $str, array $attributes = [], bool $allowInvalidOctal = false) : LNumber { Chris@0: if ('0' !== $str[0] || '0' === $str) { Chris@0: $attributes['kind'] = LNumber::KIND_DEC; Chris@0: return new LNumber((int) $str, $attributes); Chris@0: } Chris@0: Chris@0: if ('x' === $str[1] || 'X' === $str[1]) { Chris@0: $attributes['kind'] = LNumber::KIND_HEX; Chris@0: return new LNumber(hexdec($str), $attributes); Chris@0: } Chris@0: Chris@0: if ('b' === $str[1] || 'B' === $str[1]) { Chris@0: $attributes['kind'] = LNumber::KIND_BIN; Chris@0: return new LNumber(bindec($str), $attributes); Chris@0: } Chris@0: Chris@0: if (!$allowInvalidOctal && strpbrk($str, '89')) { Chris@0: throw new Error('Invalid numeric literal', $attributes); Chris@0: } Chris@0: Chris@0: // use intval instead of octdec to get proper cutting behavior with malformed numbers Chris@0: $attributes['kind'] = LNumber::KIND_OCT; Chris@0: return new LNumber(intval($str, 8), $attributes); Chris@0: } Chris@13: Chris@13: public function getType() : string { Chris@13: return 'Scalar_LNumber'; Chris@13: } Chris@0: }