mirror of
https://github.com/danog/PHP-Parser.git
synced 2024-12-12 01:19:47 +01:00
ac6f221c50
Previously the pretty printer added unnecessary and odd-looking parentheses when several operators with the same precedence were chained: 'a' . 'b' . 'c' . 'd' . 'e' // was printed as 'a' . ('b' . ('c' . ('d' . 'e'))) Another issue reported as part of #39 was that assignments inside closures were wrapped in parentheses: function() { $a = $b; } // was printed as function() { ($a = $b); } This was caused by the automatic precedence handling, which just regarded the closure as an ordinal nested expression. With the new system the $predenceMap of PrettyPrinterAbstract contains both precedence and associativity and there is a new method pPrec() which prints a node taking precedence and associativity into account. For simpler usage there are additional function pInfixOp(), pPrefixOp() and pPostfixOp(). Prints not going through pPrec() do not have any precedence handling (fixing the closure issue).
18 lines
394 B
Plaintext
18 lines
394 B
Plaintext
Closures
|
|
-----
|
|
<?php
|
|
|
|
$closureWithArgs = function ($arg1, $arg2) {
|
|
$comment = 'closure body';
|
|
};
|
|
|
|
$closureWithArgsAndVars = function ($arg1, $arg2) use($var1, $var2) {
|
|
$comment = 'closure body';
|
|
};
|
|
-----
|
|
$closureWithArgs = function ($arg1, $arg2) {
|
|
$comment = 'closure body';
|
|
};
|
|
$closureWithArgsAndVars = function ($arg1, $arg2) use($var1, $var2) {
|
|
$comment = 'closure body';
|
|
}; |