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
29 changes: 27 additions & 2 deletions Zend/zend_ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -2046,9 +2046,9 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
break;
case ZEND_AST_USE:
smart_str_appends(str, "use ");
if (ast->attr == T_FUNCTION) {
if (ast->attr == ZEND_SYMBOL_FUNCTION) {
smart_str_appends(str, "function ");
} else if (ast->attr == T_CONST) {
} else if (ast->attr == ZEND_SYMBOL_CONST) {
smart_str_appends(str, "const ");
}
goto simple_list;
Expand Down Expand Up @@ -2489,6 +2489,19 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
}
break;
case ZEND_AST_USE_ELEM:
if (ast->attr == ZEND_SYMBOL_FUNCTION) {
smart_str_appends(str, "function ");
} else if (ast->attr == ZEND_SYMBOL_CONST) {
smart_str_appends(str, "const ");
}

zend_ast_export_name(str, ast->child[0], 0, indent);

if (ast->child[1]) {
smart_str_appends(str, " as ");
zend_ast_export_name(str, ast->child[1], 0, indent);
}
break;
case ZEND_AST_TRAIT_ALIAS:
zend_ast_export_name(str, ast->child[0], 0, indent);
if (ast->attr & ZEND_ACC_PUBLIC) {
Expand All @@ -2510,6 +2523,18 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
smart_str_appends(str, ": ");
ast = ast->child[1];
goto tail_call;
case ZEND_AST_GROUP_USE:
smart_str_appends(str, "use ");
if (ast->attr == ZEND_SYMBOL_FUNCTION) {
smart_str_appends(str, "function ");
} else if (ast->attr == ZEND_SYMBOL_CONST) {
smart_str_appends(str, "const ");
}
smart_str_append(str, zend_ast_get_str(ast->child[0]));
smart_str_appends(str, "\\{");
zend_ast_export_list(str, zend_ast_get_list(ast->child[1]), true, 20, indent);
smart_str_appends(str, "}");
break;

/* 3 child nodes */
case ZEND_AST_METHOD_CALL:
Expand Down
68 changes: 68 additions & 0 deletions ext/zend_test/tests/compile_to_ast/namespace.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
--TEST--
AST can be recreated (namespace)
--EXTENSIONS--
zend_test
--FILE--
<?php

namespace Foo {
class FooTest {
}

function fn_foo() {
}

function fn_bar() {
}
}

namespace Bar {
class BarTest {
}

function fn_bar() {
}
}

namespace {
use function Bar\fn_bar;
use Foo\{function fn_foo, FooTest, function fn_bar as fn_foobar};

new FooTest();
fn_bar();
fn_foobar();

echo zend_test_compile_to_ast(file_get_contents( __FILE__ ));
}

?>
--EXPECT--
namespace Foo {
class FooTest {
}

function fn_foo() {
}

function fn_bar() {
}

}

namespace Bar {
class BarTest {
}

function fn_bar() {
}

}

namespace {
use function Bar\fn_bar;
use Foo\{function fn_foo, FooTest, function fn_bar as fn_foobar};
new FooTest();
fn_bar();
fn_foobar();
echo zend_test_compile_to_ast(file_get_contents(__FILE__));
}
Loading