Skip to content

Commit 1e83887

Browse files
committed
Emulate docComment on CONST_ELEM for PHP 7.0
1 parent dd264ec commit 1e83887

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ AST_COALESCE: left, right // prior to version 40
405405
AST_CONDITIONAL: cond, true, false
406406
AST_CONST: name
407407
AST_CONST_ELEM: name, value
408+
docComment // since version 50
408409
AST_CONTINUE: depth
409410
AST_DECLARE: declares, stmts
410411
AST_DIM: expr, dim
@@ -445,6 +446,7 @@ AST_PRE_INC: var
445446
AST_PRINT: expr
446447
AST_PROP: expr, prop
447448
AST_PROP_ELEM: name, default
449+
docComment // since version 50
448450
AST_REF: var // only used in foreach ($a as &$v)
449451
AST_RETURN: expr
450452
AST_SHELL_EXEC: expr
@@ -517,7 +519,8 @@ Supported since 2017-07-19.
517519
`AST_CLOSURE` and `AST_CLASS` now also use the normal `ast\Node` class. The `name` and
518520
`docComment` properties are now represented as children. The `endLineno` is still represented as
519521
an (undeclared) property.
520-
* `AST_PROP_ELEM` now store the `docComment` as a child, rather than a property.
522+
* `AST_PROP_ELEM` and `AST_CONST_ELEM` now store the `docComment` as a child, rather than a
523+
property.
521524
* An integer `__declId` has been added to declaration nodes of kind `AST_FUNCTION`, `AST_METHOD`,
522525
`AST_CLOSURE` and `AST_CLASS`. The `__declId` uniquely identifies a declaration within the parsed
523526
code and will remain the same if the code is parsed again. This is useful to distinguish closures

ast.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,15 @@ static void ast_fill_children_ht(HashTable *ht, zend_ast *ast, ast_state_info_t
637637

638638
}
639639

640+
#if PHP_VERSION_ID < 70100
641+
/* Emulate docComment on constants, which is not available in PHP 7.0 */
642+
if (state->version >= 50 && ast->kind == ZEND_AST_CONST_ELEM) {
643+
zval tmp;
644+
ZVAL_NULL(&tmp);
645+
zend_hash_add_new(ht, AST_STR(str_docComment), &tmp);
646+
}
647+
#endif
648+
640649
if (state->version >= 50 && ast_kind_is_decl(ast->kind)) {
641650
zval id_zval;
642651
ZVAL_LONG(&id_zval, state->declIdCounter);

0 commit comments

Comments
 (0)