#1119·PHP-Parser

Format-preserving printer loses parentheses around BooleanNot expressions

Author: maks-rafalkoCreated Oct 18, 2025Updated Oct 18, 2025

Environment

Description

When I wrap a BinaryOp\BooleanAnd node in a BooleanNot node, the format-preserving printer loses the required parentheses around the boolean AND expression. This produces semantically incorrect code.

Expected Behavior

The format-preserving printer should add parentheses around the wrapped expression:

php
$var = !(a() && b());

Actual Behavior

The parentheses are missing, changing the code's meaning:

php
$var = !a() && b();

Mutation

$stmts[0]->expr->expr = new \PhpParser\Node\Expr\BooleanNot($booleanAnd);