diff --git a/language/operators.xml b/language/operators.xml index 40c5d9a5f1db..7675d30185cc 100644 --- a/language/operators.xml +++ b/language/operators.xml @@ -54,9 +54,14 @@ Operators of equal precedence that are non-associative cannot be used next to each other, for example 1 < 2 > 1 is illegal in PHP. The expression 1 <= 1 == 1 on the - other hand is legal, because the == operator has lesser + other hand is legal, because the == operator has a lower precedence than the <= operator. + + Associativity is only meaningful for binary (and ternary) operators. + Unary operators are either prefix or postfix so this notion is not applicable. + For example !!$a can only be grouped as !(!$a). + Use of parentheses, even when not strictly necessary, can often increase readability of the code by making grouping explicit rather than relying @@ -93,6 +98,8 @@ (n/a) + + + - ++ -- ~ @@ -105,14 +112,18 @@ @ - types and increment/decrement + arithmetic (unary + and -), + increment/decrement, + bitwise, + type casting&listendand; + error control left instanceof - types + type @@ -141,8 +152,10 @@ . - arithmetic&listendand; - string + arithmetic (binary + and -), + array&listendand; + string (. prior to PHP 8.0.0) + left @@ -154,6 +167,13 @@ bitwise + + left + . + + string (as of PHP 8.0.0) + + non-associative @@ -223,10 +243,11 @@ - (n/a) + non-associative ? : ternary + (left-associative prior to PHP 8.0.0) @@ -303,7 +324,7 @@ - <literal>+</literal>, <literal>-</literal> and <literal>.</literal> have the same precedence + <literal>+</literal>, <literal>-</literal> and <literal>.</literal> have the same precedence (prior to PHP 8.0.0) + + 8.0.0 + + String concatenation (.) now has a lower precedence than + arithmetic addition/subtraction (+ and -) and + bitwise shift left/right (<< and >>); + previously it had the same precedence as + and - + and a higher precedence than << and >>. + + 8.0.0 @@ -386,6 +417,15 @@ x minus one equals 3, or so I hope previously it was left-associative. + + 7.4.0 + + Relying on the precedence of string concatenation (.) relative to + arithmetic addition/subtraction (+ or -) or + bitwise shift left/right (<< or >>), + i.e. using them together in an unparenthesized expression, is deprecated. + + 7.4.0