Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ PHP NEWS
invalid variable names). (timwolla)
. Fixed bug GH-22291 (AST pretty printing does not correctly handle braces
in string interpolation). (timwolla)
. Fixed bug GH-22373 (AST pretty-printing drops meaningful parentheses
surrounding property access). (timwolla)

- BCMath:
. Added NUL-byte validation to BCMath functions. (jorgsowa)
Expand Down
18 changes: 12 additions & 6 deletions Zend/zend_ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -2535,12 +2535,18 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
break;
case ZEND_AST_CALL: {
zend_ast *left = ast->child[0];
if (left->kind == ZEND_AST_ARROW_FUNC || left->kind == ZEND_AST_CLOSURE) {
smart_str_appendc(str, '(');
zend_ast_export_ns_name(str, left, 0, indent);
smart_str_appendc(str, ')');
} else {
zend_ast_export_ns_name(str, left, 0, indent);
switch (left->kind) {
/* ZEND_AST_ZVAL is a regular function call. */
case ZEND_AST_ZVAL:
/* ZEND_AST_VAR ($foo()) is unambiguous without parens. */
case ZEND_AST_VAR:
zend_ast_export_ns_name(str, left, 0, indent);
break;
default:
smart_str_appendc(str, '(');
zend_ast_export_ex(str, left, 0, indent);
smart_str_appendc(str, ')');
break;
}
smart_str_appendc(str, '(');
zend_ast_export_ex(str, ast->child[1], 0, indent);
Expand Down
36 changes: 36 additions & 0 deletions ext/standard/tests/assert/gh22373.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
--TEST--
GH-22373: AST pretty-printing drops meaningful parentheses surrounding property access
--FILE--
<?php

class Foo {
public static Closure $sf = strrev(...);

public function __construct(
public Closure $f = strrev(...),
) {
try {
assert(($this->f)('abc') !== 'cba');
} catch (Error $e) {
echo $e->getMessage(), PHP_EOL;
}
try {
assert(($this?->f)('abc') !== 'cba');
} catch (Error $e) {
echo $e->getMessage(), PHP_EOL;
}
try {
assert((self::$sf)('abc') !== 'cba');
} catch (Error $e) {
echo $e->getMessage(), PHP_EOL;
}
}
}

new Foo();

?>
--EXPECT--
assert(($this->f)('abc') !== 'cba')
assert(($this?->f)('abc') !== 'cba')
assert((self::$sf)('abc') !== 'cba')
Loading