The behavior of unparenthesized expressions containing both ‘.’ and ‘+’/‘-’ will change in PHP 8: ‘+’/‘-’ will take a higher precedence
Description
+/- and . operators used to have the same priority. This meant that expressions which mixed them would see them executed from left to right. This was confusing, so PHP 8.0 has made the addition the highest priority, closer to human way of reading the code.
Example
<?php
$b = 2;
$a = 'a '. $b + 1;
?>
Alternatives
- Add parenthesis to make the code less ambiguous.
Related error messages
Changed Behavior
This error may appear following an evolution in behavior, in previous versions. See dotAndMinus, dotAndPlus