Skip to content

Commit f2f7cad

Browse files
authored
Fix test failures seen in php 8.2 (#226)
Fix bug where ZEND_AST_ARROW_FUNC output for 'stmts' in php 8.2 did not match earlier php versions, which would affect tools using php-ast. Handle var_export's output changing to always be fully qualified in php 8.2 test output (`\ast\Node::__set_state(array(` starting with backslash) And start running tests in php 8.2.
1 parent fec004c commit f2f7cad

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ jobs:
3333
- PHP_VERSION: '7.3'
3434
- PHP_VERSION: '7.4'
3535
- PHP_VERSION: '8.0'
36-
- PHP_VERSION: '8.1.0RC6'
36+
- PHP_VERSION: '8.1'
37+
- PHP_VERSION: '8.2.0beta2'
3738

3839
# Steps represent a sequence of tasks that will be executed as part of the job
3940
steps:

ast.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,8 +821,18 @@ static void ast_fill_children_ht(HashTable *ht, zend_ast *ast, ast_state_info_t
821821
} else {
822822
ast_to_zval(&child_zv, child, state);
823823
}
824-
825824
if (child_name) {
825+
#if PHP_VERSION_ID >= 80200
826+
if (ast_kind == ZEND_AST_ARROW_FUNC && i == 2) {
827+
/* Imitate the native arrow function ast structure used in php 7.4-8.1 for stmts */
828+
/* (This is still different from regular functions, which have AST_STMT_LIST) */
829+
/* TODO: In a new node type, remove the ZEND_AST_RETURN node instead. */
830+
zval tmp;
831+
ast_to_zval(&tmp, child, state);
832+
ast_create_virtual_node_ex(
833+
&child_zv, ZEND_AST_RETURN, 0, zend_ast_get_lineno(child), state, 1, &tmp);
834+
}
835+
#endif
826836
zend_hash_add_new(ht, child_name, &child_zv);
827837
} else {
828838
zend_hash_next_index_insert(ht, &child_zv);

tests/php82_metadata.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ dump($metadata);
2828
dump_attributes(ast\Node::class);
2929
dump_attributes(ast\Metadata::class);
3030
--EXPECTF--
31-
ast\Node::__set_state(array(
31+
%Sast\Node::__set_state(array(
3232
'kind' => NULL,
3333
'flags' => NULL,
3434
'lineno' => NULL,
3535
'children' => NULL,
3636
'undeclaredDynamic' => 123,
3737
))
3838
Deprecated: Creation of dynamic property ast\Metadata::$undeclaredDynamic is deprecated in %sphp82_metadata.php on line 21
39-
ast\Metadata::__set_state(array(
39+
%Sast\Metadata::__set_state(array(
4040
'kind' => NULL,
4141
'name' => NULL,
4242
'flags' => NULL,

0 commit comments

Comments
 (0)