You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am here because I filed this bug at PHPStan: phpstan/phpstan#4824. It got labelled as 'easy fixes', so I looked into it. While I still don't understand that codebase at all, it seems to use PHP-Parser as parser, so the obvious place was to start here.
Basicly when I use an arrow function in combination with the and, or and xor keywords, PHP places the operator inside of the function, but PHP-Parser places the function inside of the operator...
So the example:
fn($a, $b) => $a and $b;
fn($a, $b) => $a && $b;
... is interpreted as:
// by PHP (it seems?)
fn($a, $b) => ($a and $b);
fn($a, $b) => ($a && $b);
// by PHP-Parser
(fn($a, $b) => $a) and $b;
fn($a, $b) => ($a && $b);
Current parsed result (I removed some properties to shorten the snippet):
array(
0: Stmt_Expression(
expr: Expr_BinaryOp_LogicalAnd(
left: Expr_ArrowFunction(
params: array(
0: Param(
var: Expr_Variable(
name: a
)
)
1: Param(
var: Expr_Variable(
name: b
)
)
)
expr: Expr_Variable(
name: a
)
)
right: Expr_Variable(
name: b
)
)
)
1: Stmt_Expression(
expr: Expr_ArrowFunction(
params: array(
0: Param(
var: Expr_Variable(
name: a
)
)
1: Param(
var: Expr_Variable(
name: b
)
)
)
expr: Expr_BinaryOp_BooleanAnd(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
)
)
)
Edit: cleaned up the example
The text was updated successfully, but these errors were encountered:
I am here because I filed this bug at PHPStan: phpstan/phpstan#4824. It got labelled as 'easy fixes', so I looked into it. While I still don't understand that codebase at all, it seems to use PHP-Parser as parser, so the obvious place was to start here.
See also the PHPStan playground that I made for that issue: https://phpstan.org/r/35cfa468-01c1-4aab-b8e8-816b0b3a4b66
Basicly when I use an arrow function in combination with the
and
,or
andxor
keywords, PHP places the operator inside of the function, but PHP-Parser places the function inside of the operator...So the example:
... is interpreted as:
Current parsed result (I removed some properties to shorten the snippet):
Edit: cleaned up the example
The text was updated successfully, but these errors were encountered: