## Operators

Operators.php : 31

Utility functions for use when working with operators.

##### Tags

link
  https://www.php.net/language.operators

  PHP manual on operators.

since
  1.0.0

  The `isReference()` method is based on and inspired by the method of the same name in the PHPCS native `File` class. Also see {@see \PHPCSUtils\BackCompat\BCFile}. The `isUnaryPlusMinus()` method is, in part, inspired by the `Squiz.WhiteSpace.OperatorSpacing` sniff.

### Table of Contents

isReference() : bool
  Determine if the passed token is a reference operator.
isShortTernary() : bool
  Determine whether a ternary is a short ternary/elvis operator, i.e. without "middle".
isUnaryPlusMinus() : bool
  Determine whether a T_MINUS/T_PLUS token is a unary operator.

### Methods

#### isReference()

Operators.php : 77

Determine if the passed token is a reference operator.

`public static isReference(File $phpcsFile, int $stackPtr) : bool`

Main differences with the PHPCS version:

- Defensive coding against incorrect calls to this method.
- Improved handling of select tokenizer errors involving short lists/short arrays.

##### Parameters

$phpcsFile : File

  The file being scanned.

$stackPtr : int

  The position of the `T_BITWISE_AND` token.

##### Tags

see
  File::isReference()

  Original source.

see
  BCFile::isReference()

  Cross-version compatible version of the original.

since
  1.0.0
since
  1.0.0-alpha2

  Added BC support for PHP 7.4 arrow functions.

##### Return values

bool —

`TRUE` if the specified token position represents a reference. `FALSE` if the token represents a bitwise operator.

#### isShortTernary()

Operators.php : 244

Determine whether a ternary is a short ternary/elvis operator, i.e. without "middle".

`public static isShortTernary(File $phpcsFile, int $stackPtr) : bool`

##### Parameters

$phpcsFile : File

  The file being scanned.

$stackPtr : int

  The position of the ternary then/else operator in the stack.

##### Tags

since
  1.0.0

##### Return values

bool —

`TRUE` if short ternary; or `FALSE` otherwise.

#### isUnaryPlusMinus()

Operators.php : 185

Determine whether a T_MINUS/T_PLUS token is a unary operator.

`public static isUnaryPlusMinus(File $phpcsFile, int $stackPtr) : bool`

##### Parameters

$phpcsFile : File

  The file being scanned.

$stackPtr : int

  The position of the plus/minus token.

##### Tags

since
  1.0.0

##### Return values

bool —

`TRUE` if the token passed is a unary operator. `FALSE` otherwise, i.e. if the token is an arithmetic operator, or if the token is not a `T_PLUS`/`T_MINUS` token.

## Search results