diff --git a/lib/PhpParser/PrettyPrinter/Standard.php b/lib/PhpParser/PrettyPrinter/Standard.php index 754cc4a..fb22b7a 100644 --- a/lib/PhpParser/PrettyPrinter/Standard.php +++ b/lib/PhpParser/PrettyPrinter/Standard.php @@ -316,6 +316,10 @@ class Standard extends PrettyPrinterAbstract return $this->pPrefixOp('Expr_YieldFrom', 'yield from ', $node->expr); } + public function pExpr_Print(Expr\Print_ $node) { + return $this->pPrefixOp('Expr_Print', 'print ', $node->expr); + } + // Casts public function pExpr_Cast_Int(Cast\Int_ $node) { @@ -376,10 +380,6 @@ class Standard extends PrettyPrinterAbstract return 'isset(' . $this->pCommaSeparated($node->vars) . ')'; } - public function pExpr_Print(Expr\Print_ $node) { - return 'print ' . $this->p($node->expr); - } - public function pExpr_Eval(Expr\Eval_ $node) { return 'eval(' . $this->p($node->expr) . ')'; } diff --git a/lib/PhpParser/PrettyPrinterAbstract.php b/lib/PhpParser/PrettyPrinterAbstract.php index ff1ace5..e4195ff 100644 --- a/lib/PhpParser/PrettyPrinterAbstract.php +++ b/lib/PhpParser/PrettyPrinterAbstract.php @@ -67,6 +67,7 @@ abstract class PrettyPrinterAbstract 'Expr_AssignOp_ShiftRight' => array(160, 1), 'Expr_AssignOp_Pow' => array(160, 1), 'Expr_YieldFrom' => array(165, 1), + 'Expr_Print' => array(168, 1), 'Expr_BinaryOp_LogicalAnd' => array(170, -1), 'Expr_BinaryOp_LogicalXor' => array(180, -1), 'Expr_BinaryOp_LogicalOr' => array(190, -1), diff --git a/test/code/prettyPrinter/parentheses.test b/test/code/prettyPrinter/parentheses.test index 4dbe17c..1f18b65 100644 --- a/test/code/prettyPrinter/parentheses.test +++ b/test/code/prettyPrinter/parentheses.test @@ -36,6 +36,8 @@ $a ** $b ** $c; yield from $a and yield from $b; yield from ($a and yield from $b); +print ($a and print $b); + // The following will currently add unnecessary parentheses, because the pretty printer is not aware that assignment // and incdec only work on variables. !$a = $b; @@ -67,6 +69,7 @@ $a ** $b ** $c; -1 ** 2; yield from $a and yield from $b; yield from ($a and yield from $b); +print ($a and print $b); // The following will currently add unnecessary parentheses, because the pretty printer is not aware that assignment // and incdec only work on variables. !($a = $b);