The precedence table gave "." the same precedence as "+" and "-", which is
the PHP 7 ordering. PHP 8.0 lowered "." below the arithmetic and shift
operators, so printing ('abc' . 1) + 2 produced 'abc' . 1 + 2, which PHP 8
reparses as 'abc' . (1 + 2). The same applied to "-", "<<" and ">>".
The printer already targets a specific PHP version and already varies
parenthesization by version, so select the concatenation precedence the same
way: for a target of PHP 8.0 or newer, place "." between the shift operators
and the pipe operator, matching the PHP8 block of grammar/php.y. Targets below
8.0 keep the PHP 7 table, which is correct for them and produces unchanged
output.
Fixes #1041
56 lines
1.1 KiB
Plaintext
56 lines
1.1 KiB
Plaintext
Precedence of the concatenation operator
|
|
-----
|
|
<?php
|
|
|
|
echo ('abc' . 1) + 2;
|
|
echo ('abc' . 1) - 2;
|
|
echo 2 + ('abc' . 1);
|
|
echo 'abc' . (1 + 2);
|
|
echo (1 + 2) . 'abc';
|
|
echo ('a' . 'b') << 1;
|
|
echo 'a' . (1 << 2);
|
|
echo 'a' . 'b' . 'c';
|
|
echo 'a' . ('b' . 'c');
|
|
echo ('a' . 'b') == 'c';
|
|
echo 'a' . ('b' == 'c');
|
|
-----
|
|
!!version=8.0
|
|
echo ('abc' . 1) + 2;
|
|
echo ('abc' . 1) - 2;
|
|
echo 2 + ('abc' . 1);
|
|
echo 'abc' . 1 + 2;
|
|
echo 1 + 2 . 'abc';
|
|
echo ('a' . 'b') << 1;
|
|
echo 'a' . 1 << 2;
|
|
echo 'a' . 'b' . 'c';
|
|
echo 'a' . ('b' . 'c');
|
|
echo 'a' . 'b' == 'c';
|
|
echo 'a' . ('b' == 'c');
|
|
-----
|
|
<?php
|
|
|
|
echo ('abc' . 1) + 2;
|
|
echo ('abc' . 1) - 2;
|
|
echo 2 + ('abc' . 1);
|
|
echo 'abc' . (1 + 2);
|
|
echo (1 + 2) . 'abc';
|
|
echo ('a' . 'b') << 1;
|
|
echo 'a' . (1 << 2);
|
|
echo 'a' . 'b' . 'c';
|
|
echo 'a' . ('b' . 'c');
|
|
echo ('a' . 'b') == 'c';
|
|
echo 'a' . ('b' == 'c');
|
|
-----
|
|
!!version=7.4
|
|
echo 'abc' . 1 + 2;
|
|
echo 'abc' . 1 - 2;
|
|
echo 2 + ('abc' . 1);
|
|
echo 'abc' . (1 + 2);
|
|
echo 1 + 2 . 'abc';
|
|
echo 'a' . 'b' << 1;
|
|
echo 'a' . (1 << 2);
|
|
echo 'a' . 'b' . 'c';
|
|
echo 'a' . ('b' . 'c');
|
|
echo 'a' . 'b' == 'c';
|
|
echo 'a' . ('b' == 'c');
|