We use cookies.This website uses essential cookies to operate core features. With your consent, we also use analytics cookies to understand traffic and improve the service. For more details, see our .
Was this tool helpful to use?
Your feedback helps us make it better
Search PHP 8 operator precedence, associativity, examples and English explanations.
A curated syntax reference, not a compiler or example validator. Local group numbers do not replace version-specific grammar, typing or evaluation rules. Examples keep their original code and literals. Reference
PHP 8.x precedence, including |> from PHP 8.5. Smaller levels bind more tightly. Associativity does not specify operand evaluation order; use parentheses when intent is unclear.
cloneObject CreationNot applicableCreate a shallow copy of an object; __clone can customize its state.
$copy = clone $obj;newObject CreationNot applicableCreate an instance of a class.
$user = new User();**ExponentiationRight-associativeRaise the left operand to the power of the right operand.
2 ** 10+exprUnary & Type CastingNot applicableConvert the operand to a numeric value.
+ $x-exprUnary & Type CastingNot applicableNegate the numeric operand.
- $x++exprUnary & Type CastingNot applicableIncrement, then return the updated value.
++$i--exprUnary & Type CastingNot applicableDecrement, then return the updated value.
--$iexpr++Unary & Type CastingNot applicableReturn the current value, then increment it.
$i++expr--Unary & Type CastingNot applicableReturn the current value, then decrement it.
$i--~Unary & Type CastingNot applicableInvert the bits of the operand.
~ $mask(int)Unary & Type CastingNot applicableConvert a value to an integer.
(int) "42"(float)Unary & Type CastingNot applicableConvert a value to a floating-point number.
(float) "3.14"(string)Unary & Type CastingNot applicableConvert a value to a string.
(string) 123(array)Unary & Type CastingNot applicableConvert a value to an array.
(array) $obj(object)Unary & Type CastingNot applicableConvert a value to an object.
(object) ['a' => 1](bool)Unary & Type CastingNot applicableConvert a value to a boolean.
(bool) $value@Unary & Type CastingNot applicableSuppress diagnostics for the expression where PHP permits error control.
@file_get_contents('x')instanceofType CheckingLeft-associativeTest whether an object is an instance of a class or implements an interface.
$obj instanceof User!Logical NOTNot applicableNegate the truth value of an expression.
!$ready*MultiplicativeLeft-associativeMultiply two numeric values.
$a * $b/MultiplicativeLeft-associativeDivide the left operand by the right operand.
10 / 3%MultiplicativeLeft-associativeReturn the integer division remainder.
10 % 3+AdditiveLeft-associativeAdd numbers; for arrays, + represents array union.
$a + $b-AdditiveLeft-associativeSubtract the right numeric operand from the left.
$a - $b<<Bitwise ShiftLeft-associativeShift bits to the left.
1 << 3>>Bitwise ShiftLeft-associativeShift bits to the right.
16 >> 2.String ConcatenationLeft-associativeJoin strings. In PHP 8, concatenation has lower precedence than addition, subtraction, and shifts.
"Hi " . $name|>Pipe (PHP 8.5+)Left-associativePass the left expression to the callable on the right. Available from PHP 8.5.
"hello" |> strtoupper(...)<RelationalNon-associativeCompare whether the left operand is smaller.
$a < $b<=RelationalNon-associativeCompare whether the left operand is smaller or equal.
$a <= $b>RelationalNon-associativeCompare whether the left operand is larger.
$a > $b>=RelationalNon-associativeCompare whether the left operand is larger or equal.
$a >= $b==EqualityNon-associativeCompare values using PHP type-juggling rules.
0 == '0'!=EqualityNon-associativeCompare whether values differ using PHP type-juggling rules.
$a != $b===EqualityNon-associativeCompare both type and value for equality.
0 === 0!==EqualityNon-associativeCompare whether type or value differs.
$a !== $b<>EqualityNon-associativeAlternative spelling of !=.
$a <> $b<=>EqualityNon-associativeReturn -1, 0, or 1 according to the comparison.
$a <=> $b&BitwiseLeft-associativeCombine bits using AND.
$a & $b^BitwiseLeft-associativeCombine bits using exclusive OR.
$a ^ $b|BitwiseLeft-associativeCombine bits using OR.
$a | $b&&Short-circuiting LogicLeft-associativeShort-circuit boolean AND.
$a && $b||Short-circuiting LogicLeft-associativeShort-circuit boolean OR.
$a || $b??Null CoalescingRight-associativeUse the right operand when the left expression is null or unset.
$name ?? 'anonymous'? :Ternary ConditionalNon-associativeChoose between values using a condition. Nested ternary expressions require parentheses in PHP 8.
$x > 0 ? 1 : -1=AssignmentRight-associativeAssign a value to the left-hand variable.
$x = 10+=AssignmentRight-associativeAdd and store the result.
$x += 1-=AssignmentRight-associativeSubtract and store the result.
$x -= 1*=AssignmentRight-associativeMultiply and store the result.
$x *= 2**=AssignmentRight-associativeExponentiate and store the result.
$x **= 2/=AssignmentRight-associativeDivide and store the result.
$x /= 2.=AssignmentRight-associativeConcatenate and store the result.
$msg .= ' done'%=AssignmentRight-associativeCalculate the remainder and store it.
$x %= 3&=AssignmentRight-associativeApply bitwise AND and store the result.
$x &= 0xFF|=AssignmentRight-associativeApply bitwise OR and store the result.
$x |= 0x01^=AssignmentRight-associativeApply bitwise XOR and store the result.
$x ^= $mask<<=AssignmentRight-associativeShift left and store the result.
$x <<= 2>>=AssignmentRight-associativeShift right and store the result.
$x >>= 2??=AssignmentRight-associativeAssign only when the left-hand value is null or unset.
$cfg['port'] ??= 80yield fromGeneratorsNot applicableDelegate generator values to another iterable.
yield from $items;=> (yield)GeneratorsNot applicableAssociate a yielded key with its value. This row is not the array-literal or arrow-function use of =>.
yield $key => $value;yieldGeneratorsNot applicableYield a value from a generator.
yield $value;printPrintNot applicableOutput a string using the print expression.
print $text;andLogical KeywordsLeft-associativeShort-circuit boolean AND with lower precedence than assignment.
$ok = doX() and doY()xorLogical KeywordsLeft-associativeBoolean exclusive OR with lower precedence than assignment.
$a xor $borLogical KeywordsLeft-associativeShort-circuit boolean OR with lower precedence than assignment.
$fp = fopen($f, 'r') or die('open fail')includeInclude / RequireNot applicableEvaluate a file. Include expressions have the low precedence documented by the PHP manual.
include $file;include_onceInclude / RequireNot applicableInclude a file once during a script execution.
include_once $file;requireInclude / RequireNot applicableEvaluate a required file; failure has stronger error behavior than include.
require $file;require_onceInclude / RequireNot applicableRequire a file once during a script execution.
require_once $file;fn (...) =>Arrow FunctionsNot applicableDefine an arrow function expression.
fn($x) => $x + 1throwThrowNot applicableThrow an exception; usable as an expression in PHP 8.
throw new RuntimeException("error");Overview
Understand what the tool solves, how it works, and the boundaries of its data.
This reference helps you find a PHP operator by symbol, name, description, example, or displayed precedence level. Results show a short explanation, an example, the operator category, its associativity label, and its position in the list. You can narrow results by category and associativity, then copy a symbol or example for use in your own notes.
Precedence describes grouping: it tells you which operator binds more tightly when an expression has no parentheses. The displayed level is an ordering aid for this reference; a smaller number means a tighter binding. It is not a numeric value defined by PHP. Associativity describes grouping when operators of the same precedence appear together: for example, subtraction groups left to right, while assignment groups right to left. The PHP manual explains these rules and their version history in its operator precedence table.
The reference includes familiar groups such as arithmetic, comparisons, bitwise and logical operators, assignment, null coalescing, generators, and language constructs. PHP 8 changed the relative precedence of the string concatenation dot (.) and arithmetic operators; PHP 8 also made the ternary operator non-associative. PHP 8.5 adds the pipe operator (|>), which passes a value to a callable on its right. Check the manual for the exact behavior relevant to your PHP version, especially when maintaining code across versions.
Guide
Follow the workflow and verify inputs and outputs with practical examples.
Enter an operator such as ??, a name such as “assignment,” a word from an explanation or example, or a displayed level number. Search matches these fields within the reference entries; it does not accept a complete PHP expression for parsing.
Choose an operator category, an associativity value, or both. Return each filter to “All” to broaden the list. The result count updates with the filters, and matching entries are grouped by their displayed level.
Compare the symbol, category, associativity, description, and sample expression. Copy a symbol or sample if useful, then add parentheses to your own expression where they make the intended grouping clear.
For example, search and and compare it with &&. Both are logical operators, but the word operator has lower precedence than assignment. That distinction can change how an assignment expression is grouped.
Use cases
See how the tool fits into real work and everyday tasks.
When reviewing a condition with comparisons, bitwise operators, or short-circuit logic, filter to the relevant category and confirm the grouping before suggesting explicit parentheses.
When studying PHP 8 behavior, find the dot operator or ternary entry, then compare the note with the manual’s version-specific explanation before changing older code.
Use the matching example and associativity label to anchor a code review discussion. Treat the entry as a pointer to the rule, then check the project’s target PHP version and test the actual expression.
Q&A
Find concise answers to common questions and confusing cases.
No. Precedence and associativity describe how an expression is grouped, not the runtime order in which its operands are evaluated. Avoid relying on a particular evaluation order when an operand has side effects; consult the PHP manual and simplify or split the expression.
and behave differently from &&?They have different precedence. The word operator and binds less tightly than assignment, while && binds more tightly. If you combine either with assignment, use parentheses to show whether the assignment or the logical operation should form the larger group.
No. It filters reference entries and displays their supplied descriptions and examples. It does not parse or execute your expression, report syntax errors, or verify behavior on a PHP installation.
No. The PHP manual documents |> as available in PHP 8.5 and later. Confirm the runtime version before using it; earlier PHP releases do not support this operator.
Notes
Review scope, result limitations, and important precautions before use.
This is a lookup aid, not an expression parser, syntax checker, or execution environment. Its examples illustrate entries rather than proving how a larger expression behaves. Operator rules can differ by PHP version, and the displayed level is a convenient ordering label rather than an official PHP numeric precedence value. For migrations or code where grouping matters, consult the relevant version of the PHP precedence documentation, add parentheses to make intent explicit, and run tests on the project’s target PHP version. The PHP manual notes that precedence and associativity do not determine general operand evaluation order.
Checked against the PHP documentation on October 2, 2026: the manual covers the precedence table and version notes; the functional operators page describes the PHP 8.5 pipe operator.
Related
Discover related tools, collections, and available API capabilities.