Expressions And Operators: Operator Precedence

The precedence of Hack operators is shown in the table below.

Operators higher in the table have a higher precedence (binding more tightly). Binary operators on the same row are evaluated according to their associativity.

Operator Description Associativity
\ Namespace separator Left
:: Scope resolution Left
[] Index resolution for Hack Arrays and Strings Left
->, ?-> Property selection and null-safe property selection Left
new Object creation & Memory allocation None
#, () Enum class labels and Function calling Left
clone Object cloning (shallowly, not deeply) None
readonly, await, ++ -- (postfix) Using readonly, Suspending an async function, and Incrementing / Decrementing (postfix) Right
(int) (float) (string), **, @, ++ -- (prefix) Casting, Exponentiation, Suppressing errors, and Incrementing / Decrementing (prefix) Right
is, as ?as Type checks / Type assertions Left
!, ~, + - (one argument) Logical negation, Bitwise negation, and Unary Addition / Subtraction Right
* / % Multiplication, Division, and Modulo Left
., + - (two arguments) String concatenation and Addition / Subtraction Left
<< >> Bitwise shifting (left and right) Left
< <= > >=, <=> Comparison operators and Spaceship operator None
=== !== == != Equality operators None
& Bitwise AND Left
^ Bitwise XOR Left
| Bitwise OR Left
&& Logical AND Left
|| Logical OR Left
?? Coalesce operator Right
? :, ?: Ternary evaluation and Elvis operator Left
|> Pipe / Chain function calls Left
= += -= .= *= /= %= <<= >>= &= ^= |=, ??= Assignment operators and Coalescing assignment operator Right
echo Write to standard output Right
include require Include or Require a script Left
Was This Page Useful?
Thank You!
Thank You! If you'd like to share more feedback, please file an issue.