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

Breadcrumb

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

function PrettyPrinterAbstract::newOperandRequiresParens

Determines whether an expression used in "new" or "instanceof" requires parentheses.

Parameters

Node $node New or instanceof operand:

Return value

bool Whether parentheses are required

2 calls to PrettyPrinterAbstract::newOperandRequiresParens()
PrettyPrinterAbstract::pFixup in vendor/nikic/php-parser/lib/PhpParser/PrettyPrinterAbstract.php
Print node with fixups.
Standard::pNewOperand in vendor/nikic/php-parser/lib/PhpParser/PrettyPrinter/Standard.php

File

vendor/nikic/php-parser/lib/PhpParser/PrettyPrinterAbstract.php, line 1198

Class

PrettyPrinterAbstract

Namespace

PhpParser

Code

protected function newOperandRequiresParens(Node $node) : bool {
    if ($node instanceof Node\Name || $node instanceof Expr\Variable) {
        return false;
    }
    if ($node instanceof Expr\ArrayDimFetch || $node instanceof Expr\PropertyFetch || $node instanceof Expr\NullsafePropertyFetch) {
        return $this->newOperandRequiresParens($node->var);
    }
    if ($node instanceof Expr\StaticPropertyFetch) {
        return $this->newOperandRequiresParens($node->class);
    }
    return true;
}

API Navigation

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