Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Zend/tests/halt_compiler_wo_parentheses1.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
--TEST--
__HALT_COMPILER;
--FILE--
<?php echo 'test'; var_dump(__COMPILER_HALT_OFFSET__); __HALT_COMPILER;
?>
===DONE===
--EXPECT--
testint(71)
21 changes: 21 additions & 0 deletions Zend/tests/halt_compiler_wo_parentheses2.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
__HALT_COMPILER; 2 files
--FILE--
<?php
$text = "<?php echo 'test'; var_dump(__COMPILER_HALT_OFFSET__); __HALT_COMPILER; ?>
hi there";
file_put_contents(__DIR__ . '/test1.php', $text);
$text = "<?php echo 'test2'; var_dump(__COMPILER_HALT_OFFSET__); __HALT_COMPILER; ?>
hi there 2";
file_put_contents(__DIR__ . '/test2.php', $text);
include __DIR__ . '/test1.php';
include __DIR__ . '/test2.php';
?>
--CLEAN--
<?php
unlink(__DIR__ . '/test1.php');
unlink(__DIR__ . '/test2.php');
?>
--EXPECT--
testint(71)
test2int(72)
17 changes: 14 additions & 3 deletions Zend/zend_language_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
%type <ast> identifier type_expr_without_static union_type_without_static
%type <ast> inline_function union_type
%type <ast> attributed_statement attributed_class_statement attributed_parameter
%type <ast> attribute_decl attribute attributes
%type <ast> attribute_decl attribute attributes halt_compiler_statement

%type <num> returns_ref function fn is_reference is_variadic variable_modifiers
%type <num> method_modifiers non_empty_member_modifiers member_modifier optional_visibility_modifier
Expand Down Expand Up @@ -344,6 +344,10 @@ top_statement:
statement { $$ = $1; }
| attributed_statement { $$ = $1; }
| attributes attributed_statement { $$ = zend_ast_with_attributes($2, $1); }
| T_HALT_COMPILER ';'
{ $$ = zend_ast_create(ZEND_AST_HALT_COMPILER,
zend_ast_create_zval_from_long(zend_get_scanned_file_offset()));
zend_stop_lexing(); }
| T_HALT_COMPILER '(' ')' ';'
{ $$ = zend_ast_create(ZEND_AST_HALT_COMPILER,
zend_ast_create_zval_from_long(zend_get_scanned_file_offset()));
Expand Down Expand Up @@ -443,12 +447,19 @@ inner_statement:
statement { $$ = $1; }
| attributed_statement { $$ = $1; }
| attributes attributed_statement { $$ = zend_ast_with_attributes($2, $1); }
| T_HALT_COMPILER '(' ')' ';'
{ $$ = NULL; zend_throw_exception(zend_ce_compile_error,
| halt_compiler_statement { $$ = $1; zend_throw_exception(zend_ce_compile_error,
"__HALT_COMPILER() can only be used from the outermost scope", 0); YYERROR; }
;


halt_compiler_statement:
T_HALT_COMPILER ';'
{ $$ = NULL; }
| T_HALT_COMPILER '(' ')' ';'
{ $$ = NULL; }
;


statement:
'{' inner_statement_list '}' { $$ = $2; }
| if_stmt { $$ = $1; }
Expand Down