Format-preserving printer loses parentheses around BooleanNot expressions
Author: maks-rafalkoCreated Oct 18, 2025Updated Oct 18, 2025
Environment
- PHP-Parser Version: 5.6.1
- PHP Version: 8.4.4
- Reproducer: https://github.com/nikic/PHP-Parser/pull/1120
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:
$var = !(a() && b());Actual Behavior
The parentheses are missing, changing the code's meaning:
$var = !a() && b();Mutation
$stmts[0]->expr->expr = new \PhpParser\Node\Expr\BooleanNot($booleanAnd);Source: nikic/PHP-Parser