PHP 7.3: Unparenthesized expressions containing '.' and '+'/'-' both are deprecated
PHP 7.3 raises a deprecation notice when the concat operator (.
) and +
/-
operators are used in the same expression without parenthesis. This is to mitigate the code ambiguity, and to prepare to set the strict order of operators.
For example, the following snippet will raise a deprecation notice:
echo 'Total' . 5 + 5;
Deprecated: The behavior of unparenthesized expressions containing both '.' and '+'/'-' will change in PHP 8: '+'/'-' will take a higher precedence in ... on line ...
From PHP 8 and later, this will be evaluated as 'total' + (5 + 5)
, with the +
and -
operators taking higher precedence.
You can avoid the deprecation notice and make your code more readable by simply using parenthesis to convey the correct meaning.