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
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ PHP NEWS
(Marti2203).
. Fixed bug GH-24989 (Use-after-free in GC when an exception is thrown).
(David Carlier)
. Fixed AST export dropping parentheses around the class operand of static
property fetches, static method calls and class constant fetches.
(Jorg Sowa)

- CLI:
. Fixed bug GH-24697 (PHP_HTTP_PARSER_STRICT build option doesn't work).
Expand Down
35 changes: 35 additions & 0 deletions Zend/tests/assert/ast_export_static_parens.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--TEST--
assert() message keeps parentheses around the class operand of ::
--INI--
zend.assertions=1
--FILE--
<?php
class C {
const X = false;
public static $x = false;
public static function m() { return false; }
}

$a = null;
$c = new C;

$tests = [
fn() => assert(($a ?? $c)::$x),
fn() => assert(($a ?? $c)::m()),
fn() => assert(($a ?? $c)::X),
fn() => assert(($a ?? $c)::class === 'D'),
];

foreach ($tests as $test) {
try {
$test();
} catch (AssertionError $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
}
?>
--EXPECT--
AssertionError: assert(($a ?? $c)::$x)
AssertionError: assert(($a ?? $c)::m())
AssertionError: assert(($a ?? $c)::X)
AssertionError: assert(($a ?? $c)::class === 'D')
8 changes: 4 additions & 4 deletions Zend/zend_ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -2205,7 +2205,7 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
zend_ast_export_var(str, ast->child[1], 0, indent);
break;
case ZEND_AST_STATIC_PROP:
zend_ast_export_ns_name(str, ast->child[0], 0, indent);
zend_ast_export_ns_name(str, ast->child[0], 260, indent);
smart_str_appends(str, "::$");
zend_ast_export_var(str, ast->child[1], 0, indent);
break;
Expand All @@ -2225,7 +2225,7 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
smart_str_appends(str, "...");
break;
case ZEND_AST_CLASS_CONST:
zend_ast_export_ns_name(str, ast->child[0], 0, indent);
zend_ast_export_ns_name(str, ast->child[0], 260, indent);
smart_str_appends(str, "::");
zend_ast_export_name(str, ast->child[1], 0, indent);
break;
Expand All @@ -2242,7 +2242,7 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
EMPTY_SWITCH_DEFAULT_CASE()
}
} else {
zend_ast_export_ns_name(str, ast->child[0], 0, indent);
zend_ast_export_ns_name(str, ast->child[0], 260, indent);
}
smart_str_appends(str, "::class");
break;
Expand Down Expand Up @@ -2547,7 +2547,7 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
smart_str_appendc(str, ')');
break;
case ZEND_AST_STATIC_CALL:
zend_ast_export_ns_name(str, ast->child[0], 0, indent);
zend_ast_export_ns_name(str, ast->child[0], 260, indent);
smart_str_appends(str, "::");
zend_ast_export_var(str, ast->child[1], 0, indent);
smart_str_appendc(str, '(');
Expand Down
Loading