Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Int_.php

class Int_

Same name in this branch
  1. 11.1.x vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/Int_.php \PhpParser\Node\Expr\Cast\Int_

Hierarchy

  • class \PhpParser\NodeAbstract implements \PhpParser\Node, \PhpParser\JsonSerializable
    • class \PhpParser\Node\Expr extends \PhpParser\NodeAbstract
      • class \PhpParser\Node\Scalar extends \PhpParser\Node\Expr
        • class \PhpParser\Node\Scalar\Int_ extends \PhpParser\Node\Scalar

Expanded class hierarchy of Int_

2 files declare their use of Int_
NodeDumper.php in vendor/nikic/php-parser/lib/PhpParser/NodeDumper.php
ParserAbstract.php in vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php

File

vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/Int_.php, line 8

Namespace

PhpParser\Node\Scalar
View source
class Int_ extends Scalar {
    
    /* For use in "kind" attribute */
    public const KIND_BIN = 2;
    public const KIND_OCT = 8;
    public const KIND_DEC = 10;
    public const KIND_HEX = 16;
    
    /** @var int Number value */
    public int $value;
    
    /**
     * Constructs an integer number scalar node.
     *
     * @param int $value Value of the number
     * @param array<string, mixed> $attributes Additional attributes
     */
    public function __construct(int $value, array $attributes = []) {
        $this->attributes = $attributes;
        $this->value = $value;
    }
    public function getSubNodeNames() : array {
        return [
            'value',
        ];
    }
    
    /**
     * Constructs an Int node from a string number literal.
     *
     * @param string $str String number literal (decimal, octal, hex or binary)
     * @param array<string, mixed> $attributes Additional attributes
     * @param bool $allowInvalidOctal Whether to allow invalid octal numbers (PHP 5)
     *
     * @return Int_ The constructed LNumber, including kind attribute
     */
    public static function fromString(string $str, array $attributes = [], bool $allowInvalidOctal = false) : Int_ {
        $attributes['rawValue'] = $str;
        $str = str_replace('_', '', $str);
        if ('0' !== $str[0] || '0' === $str) {
            $attributes['kind'] = Int_::KIND_DEC;
            return new Int_((int) $str, $attributes);
        }
        if ('x' === $str[1] || 'X' === $str[1]) {
            $attributes['kind'] = Int_::KIND_HEX;
            return new Int_(hexdec($str), $attributes);
        }
        if ('b' === $str[1] || 'B' === $str[1]) {
            $attributes['kind'] = Int_::KIND_BIN;
            return new Int_(bindec($str), $attributes);
        }
        if (!$allowInvalidOctal && strpbrk($str, '89')) {
            throw new Error('Invalid numeric literal', $attributes);
        }
        // Strip optional explicit octal prefix.
        if ('o' === $str[1] || 'O' === $str[1]) {
            $str = substr($str, 2);
        }
        // use intval instead of octdec to get proper cutting behavior with malformed numbers
        $attributes['kind'] = Int_::KIND_OCT;
        return new Int_(intval($str, 8), $attributes);
    }
    public function getType() : string {
        return 'Scalar_Int';
    }

}

Members

Title Sort descending Modifiers Object type Summary
Int_::$value public property @var int Number value
Int_::fromString public static function Constructs an Int node from a string number literal.
Int_::getSubNodeNames public function
Int_::getType public function
Int_::KIND_BIN public constant
Int_::KIND_DEC public constant
Int_::KIND_HEX public constant
Int_::KIND_OCT public constant
Int_::__construct public function Constructs an integer number scalar node.

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal