Skip to content

Commit 8ee2a98

Browse files
committed
fix: dump heredoc tags
1 parent 9040e79 commit 8ee2a98

File tree

4 files changed

+39
-5
lines changed

4 files changed

+39
-5
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Dump heredoc tags
3+
--INI--
4+
zend.assertions=1
5+
--FILE--
6+
<?php
7+
try {
8+
assert(false &&
9+
<<<HTML
10+
val inside
11+
HTML
12+
);
13+
} catch(\Throwable $e) {
14+
echo $e->getMessage();
15+
}
16+
17+
?>
18+
--EXPECT--
19+
assert(false && <<<HEREDOC
20+
val inside
21+
HEREDOC)

Zend/zend_ast.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,8 +1630,10 @@ static ZEND_COLD void zend_ast_export_if_stmt(smart_str *str, zend_ast_list *lis
16301630
smart_str_appendc(str, '}');
16311631
}
16321632

1633-
static ZEND_COLD void zend_ast_export_zval(smart_str *str, zval *zv, int priority, int indent)
1633+
static ZEND_COLD void zend_ast_export_zval(smart_str *str, zend_ast *ast, int priority, int indent)
16341634
{
1635+
zval *zv = zend_ast_get_zval(ast);
1636+
16351637
ZVAL_DEREF(zv);
16361638
switch (Z_TYPE_P(zv)) {
16371639
case IS_NULL:
@@ -1651,9 +1653,15 @@ static ZEND_COLD void zend_ast_export_zval(smart_str *str, zval *zv, int priorit
16511653
str, Z_DVAL_P(zv), (int) EG(precision), /* zero_fraction */ false);
16521654
break;
16531655
case IS_STRING:
1654-
smart_str_appendc(str, '\'');
1655-
zend_ast_export_str(str, Z_STR_P(zv));
1656-
smart_str_appendc(str, '\'');
1656+
if (ast->attr & ZEND_NAME_HEREDOC) {
1657+
smart_str_appends(str, "<<<HEREDOC\n");
1658+
zend_ast_export_str(str, Z_STR_P(zv));
1659+
smart_str_appends(str, "\nHEREDOC");
1660+
} else {
1661+
smart_str_appendc(str, '\'');
1662+
zend_ast_export_str(str, Z_STR_P(zv));
1663+
smart_str_appendc(str, '\'');
1664+
}
16571665
break;
16581666
case IS_ARRAY: {
16591667
zend_long idx;
@@ -1878,7 +1886,7 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
18781886
switch (ast->kind) {
18791887
/* special nodes */
18801888
case ZEND_AST_ZVAL:
1881-
zend_ast_export_zval(str, zend_ast_get_zval(ast), priority, indent);
1889+
zend_ast_export_zval(str, ast, priority, indent);
18821890
break;
18831891
case ZEND_AST_CONSTANT: {
18841892
zend_string *name = zend_ast_get_constant_name(ast);

Zend/zend_compile.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,7 @@ ZEND_API zend_string *zend_type_to_string(zend_type type);
10341034
#define ZEND_NAME_FQ 0
10351035
#define ZEND_NAME_NOT_FQ 1
10361036
#define ZEND_NAME_RELATIVE 2
1037+
#define ZEND_NAME_HEREDOC 3
10371038

10381039
/* ZEND_FETCH_ flags in class name AST of new const expression must not clash with ZEND_NAME_ flags */
10391040
#define ZEND_CONST_EXPR_NEW_FETCH_TYPE_SHIFT 2

Zend/zend_language_scanner.l

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3132,6 +3132,10 @@ emit_token_with_val:
31323132
if (PARSER_MODE()) {
31333133
ZEND_ASSERT(Z_TYPE_P(zendlval) != IS_UNDEF);
31343134
elem->ast = zend_ast_create_zval_with_lineno(zendlval, start_line);
3135+
zend_ptr_stack *stack = &SCNG(heredoc_label_stack);
3136+
if (stack->elements) {
3137+
elem->ast->attr |= ZEND_NAME_HEREDOC;
3138+
}
31353139
}
31363140
31373141
emit_token:

0 commit comments

Comments
 (0)