diff --git a/lib/PhpParser/PrettyPrinter/Standard.php b/lib/PhpParser/PrettyPrinter/Standard.php index 99cfd17c..941bab44 100644 --- a/lib/PhpParser/PrettyPrinter/Standard.php +++ b/lib/PhpParser/PrettyPrinter/Standard.php @@ -622,7 +622,7 @@ class Standard extends PrettyPrinterAbstract return $this->pAttrGroups($node->attrGroups, true) . ($node->static ? 'static ' : '') . 'function ' . ($node->byRef ? '&' : '') - . '(' . $this->pCommaSeparated($node->params) . ')' + . '(' . $this->pMaybeMultiline($node->params) . ')' . (!empty($node->uses) ? ' use (' . $this->pCommaSeparated($node->uses) . ')' : '') . (null !== $node->returnType ? ': ' . $this->p($node->returnType) : '') . ' {' . $this->pStmts($node->stmts) . $this->nl . '}'; @@ -644,7 +644,7 @@ class Standard extends PrettyPrinterAbstract return $this->pAttrGroups($node->attrGroups, true) . ($node->static ? 'static ' : '') . 'fn' . ($node->byRef ? '&' : '') - . '(' . $this->pCommaSeparated($node->params) . ')' + . '(' . $this->pMaybeMultiline($node->params) . ')' . (null !== $node->returnType ? ': ' . $this->p($node->returnType) : '') . ' => ' . $this->p($node->expr); @@ -813,7 +813,7 @@ class Standard extends PrettyPrinterAbstract protected function pStmt_Function(Stmt\Function_ $node) { return $this->pAttrGroups($node->attrGroups) . 'function ' . ($node->byRef ? '&' : '') . $node->name - . '(' . $this->pCommaSeparated($node->params) . ')' + . '(' . $this->pMaybeMultiline($node->params) . ')' . (null !== $node->returnType ? ': ' . $this->p($node->returnType) : '') . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}'; } diff --git a/test/code/prettyPrinter/stmt/param_comments.test b/test/code/prettyPrinter/stmt/param_comments.test new file mode 100644 index 00000000..23f809ea --- /dev/null +++ b/test/code/prettyPrinter/stmt/param_comments.test @@ -0,0 +1,53 @@ +Comments on function parameters +----- + 42; +----- +class Test +{ + function test( + // Comment + $param + ) + { + } +} +function test( + // Comment + $param +) +{ +} +function ( + // Comment + $param +) { +}; +fn( + // Comment + $param +) => 42;