Skip to content

Commit feb6bf7

Browse files
committed
Wrap class const LHS in parens if necessary
This looks like a very old bug in the pretty printer that showed up in PHP 8 tests.
1 parent 0cee208 commit feb6bf7

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

lib/PhpParser/PrettyPrinter/Standard.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ protected function pExpr_ConstFetch(Expr\ConstFetch $node) {
577577
}
578578

579579
protected function pExpr_ClassConstFetch(Expr\ClassConstFetch $node) {
580-
return $this->p($node->class) . '::' . $this->p($node->name);
580+
return $this->pDereferenceLhs($node->class) . '::' . $this->p($node->name);
581581
}
582582

583583
protected function pExpr_PropertyFetch(Expr\PropertyFetch $node) {

lib/PhpParser/PrettyPrinterAbstract.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,9 @@ protected function initializeFixupMap() {
11571157
'var' => self::FIXUP_DEREF_LHS,
11581158
'name' => self::FIXUP_BRACED_NAME,
11591159
],
1160+
Expr\ClassConstFetch::class => [
1161+
'var' => self::FIXUP_DEREF_LHS,
1162+
],
11601163
Scalar\Encapsed::class => [
11611164
'parts' => self::FIXUP_ENCAPSED,
11621165
],

test/code/prettyPrinter/expr/uvs.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ $A::{$b[$c]}();
1010
A::$$b[$c]();
1111
($a->b)();
1212
(A::$b)();
13+
('a' . 'b')::X;
1314
-----
1415
!!php7
1516
(function () {
@@ -21,3 +22,4 @@ $A::{$b[$c]}();
2122
A::${$b}[$c]();
2223
($a->b)();
2324
(A::$b)();
25+
('a' . 'b')::X;

0 commit comments

Comments
 (0)