-
Notifications
You must be signed in to change notification settings - Fork 7.9k
zend_ast: Preserve heredocs in zend_ast_export() #18690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
xepozz
wants to merge
2
commits into
php:master
Choose a base branch
from
xepozz:here-ast-printer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--TEST-- | ||
Dump heredoc tags | ||
--INI-- | ||
zend.assertions=1 | ||
--FILE-- | ||
<?php | ||
try { | ||
assert(false && | ||
<<<HTML | ||
val inside | ||
HTML | ||
); | ||
} catch(\Throwable $e) { | ||
echo $e->getMessage(); | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
assert(false && <<<HEREDOC | ||
val inside | ||
HEREDOC) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1630,8 +1630,10 @@ static ZEND_COLD void zend_ast_export_if_stmt(smart_str *str, zend_ast_list *lis | |||||
smart_str_appendc(str, '}'); | ||||||
} | ||||||
|
||||||
static ZEND_COLD void zend_ast_export_zval(smart_str *str, zval *zv, int priority, int indent) | ||||||
static ZEND_COLD void zend_ast_export_zval(smart_str *str, zend_ast *ast, int priority, int indent) | ||||||
{ | ||||||
zval *zv = zend_ast_get_zval(ast); | ||||||
|
||||||
ZVAL_DEREF(zv); | ||||||
switch (Z_TYPE_P(zv)) { | ||||||
case IS_NULL: | ||||||
|
@@ -1651,9 +1653,15 @@ static ZEND_COLD void zend_ast_export_zval(smart_str *str, zval *zv, int priorit | |||||
str, Z_DVAL_P(zv), (int) EG(precision), /* zero_fraction */ false); | ||||||
break; | ||||||
case IS_STRING: | ||||||
smart_str_appendc(str, '\''); | ||||||
zend_ast_export_str(str, Z_STR_P(zv)); | ||||||
smart_str_appendc(str, '\''); | ||||||
if (ast->attr & ZEND_NAME_HEREDOC) { | ||||||
smart_str_appends(str, "<<<HEREDOC\n"); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
zend_ast_export_str(str, Z_STR_P(zv)); | ||||||
smart_str_appends(str, "\nHEREDOC"); | ||||||
} else { | ||||||
smart_str_appendc(str, '\''); | ||||||
zend_ast_export_str(str, Z_STR_P(zv)); | ||||||
smart_str_appendc(str, '\''); | ||||||
} | ||||||
break; | ||||||
case IS_ARRAY: { | ||||||
zend_long idx; | ||||||
|
@@ -1878,7 +1886,7 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio | |||||
switch (ast->kind) { | ||||||
/* special nodes */ | ||||||
case ZEND_AST_ZVAL: | ||||||
zend_ast_export_zval(str, zend_ast_get_zval(ast), priority, indent); | ||||||
zend_ast_export_zval(str, ast, priority, indent); | ||||||
break; | ||||||
case ZEND_AST_CONSTANT: { | ||||||
zend_string *name = zend_ast_get_constant_name(ast); | ||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would happen if:
HEREDOC
?zend_ast_export_str()
?Is it guaranteed that the output is valid PHP in all cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll cover these with tests, thanks.