Skip to content

Commit 84cf35b

Browse files
committed
Merge branch 'PHP-8.6'
* PHP-8.6: zend_test: Fix function and constant imports in compile_to_ast and add support for grouping
2 parents 29b5e16 + d03c80e commit 84cf35b

2 files changed

Lines changed: 95 additions & 2 deletions

File tree

‎Zend/zend_ast.c‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2531,9 +2531,9 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
25312531
break;
25322532
case ZEND_AST_USE:
25332533
smart_str_appends(str, "use ");
2534-
if (ast->attr == T_FUNCTION) {
2534+
if (ast->attr == ZEND_SYMBOL_FUNCTION) {
25352535
smart_str_appends(str, "function ");
2536-
} else if (ast->attr == T_CONST) {
2536+
} else if (ast->attr == ZEND_SYMBOL_CONST) {
25372537
smart_str_appends(str, "const ");
25382538
}
25392539
goto simple_list;
@@ -2973,6 +2973,19 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
29732973
}
29742974
break;
29752975
case ZEND_AST_USE_ELEM:
2976+
if (ast->attr == ZEND_SYMBOL_FUNCTION) {
2977+
smart_str_appends(str, "function ");
2978+
} else if (ast->attr == ZEND_SYMBOL_CONST) {
2979+
smart_str_appends(str, "const ");
2980+
}
2981+
2982+
zend_ast_export_name(str, ast->child[0], 0, indent);
2983+
2984+
if (ast->child[1]) {
2985+
smart_str_appends(str, " as ");
2986+
zend_ast_export_name(str, ast->child[1], 0, indent);
2987+
}
2988+
break;
29762989
case ZEND_AST_TRAIT_ALIAS:
29772990
zend_ast_export_name(str, ast->child[0], 0, indent);
29782991
if (ast->attr & ZEND_ACC_PUBLIC) {
@@ -2994,6 +3007,18 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
29943007
smart_str_appends(str, ": ");
29953008
ast = ast->child[1];
29963009
goto tail_call;
3010+
case ZEND_AST_GROUP_USE:
3011+
smart_str_appends(str, "use ");
3012+
if (ast->attr == ZEND_SYMBOL_FUNCTION) {
3013+
smart_str_appends(str, "function ");
3014+
} else if (ast->attr == ZEND_SYMBOL_CONST) {
3015+
smart_str_appends(str, "const ");
3016+
}
3017+
smart_str_append(str, zend_ast_get_str(ast->child[0]));
3018+
smart_str_appends(str, "\\{");
3019+
zend_ast_export_list(str, zend_ast_get_list(ast->child[1]), true, 20, indent);
3020+
smart_str_appends(str, "}");
3021+
break;
29973022

29983023
/* 3 child nodes */
29993024
case ZEND_AST_METHOD_CALL:
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
--TEST--
2+
AST can be recreated (namespace)
3+
--EXTENSIONS--
4+
zend_test
5+
--FILE--
6+
<?php
7+
8+
namespace Foo {
9+
class FooTest {
10+
}
11+
12+
function fn_foo() {
13+
}
14+
15+
function fn_bar() {
16+
}
17+
}
18+
19+
namespace Bar {
20+
class BarTest {
21+
}
22+
23+
function fn_bar() {
24+
}
25+
}
26+
27+
namespace {
28+
use function Bar\fn_bar;
29+
use Foo\{function fn_foo, FooTest, function fn_bar as fn_foobar};
30+
31+
new FooTest();
32+
fn_bar();
33+
fn_foobar();
34+
35+
echo zend_test_compile_to_ast(file_get_contents( __FILE__ ));
36+
}
37+
38+
?>
39+
--EXPECT--
40+
namespace Foo {
41+
class FooTest {
42+
}
43+
44+
function fn_foo() {
45+
}
46+
47+
function fn_bar() {
48+
}
49+
50+
}
51+
52+
namespace Bar {
53+
class BarTest {
54+
}
55+
56+
function fn_bar() {
57+
}
58+
59+
}
60+
61+
namespace {
62+
use function Bar\fn_bar;
63+
use Foo\{function fn_foo, FooTest, function fn_bar as fn_foobar};
64+
new FooTest();
65+
fn_bar();
66+
fn_foobar();
67+
echo zend_test_compile_to_ast(file_get_contents(__FILE__));
68+
}

0 commit comments

Comments
 (0)