Skip to content

Commit 359ce15

Browse files
committed
zend_test: Backport zend_test_compile_to_ast() function
This was introduced in 8.5. We need this in 8.4 too to debug AST dumping (see phpGH-24418).
1 parent b232da5 commit 359ce15

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎ext/zend_test/test.c‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,6 +1792,28 @@ static PHP_FUNCTION(zend_test_create_throwing_resource)
17921792
ZVAL_RES(return_value, res);
17931793
}
17941794

1795+
static PHP_FUNCTION(zend_test_compile_to_ast)
1796+
{
1797+
zend_string *str;
1798+
1799+
ZEND_PARSE_PARAMETERS_START(1, 1)
1800+
Z_PARAM_STR(str)
1801+
ZEND_PARSE_PARAMETERS_END();
1802+
1803+
zend_arena *ast_arena;
1804+
zend_ast *ast = zend_compile_string_to_ast(str, &ast_arena, ZSTR_EMPTY_ALLOC());
1805+
if (!ast) {
1806+
RETURN_THROWS();
1807+
}
1808+
1809+
zend_string *result = zend_ast_export("", ast, "");
1810+
1811+
zend_ast_destroy(ast);
1812+
zend_arena_destroy(ast_arena);
1813+
1814+
RETVAL_STR(result);
1815+
}
1816+
17951817
static PHP_FUNCTION(zend_test_gh18756)
17961818
{
17971819
ZEND_PARSE_PARAMETERS_NONE();

‎ext/zend_test/test.stub.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,8 @@ function zend_test_is_zend_ptr(int $addr): bool {}
330330

331331
function zend_test_log_err_debug(string $str): void {}
332332

333+
function zend_test_compile_to_ast(string $str): string {}
334+
333335
function zend_test_gh18756(): void {}
334336

335337
/** @compile-time-eval */

‎ext/zend_test/test_arginfo.h‎

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)