Skip to content

Support __halt_compiler as a member of the top level statements #381

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

Closed
TysonAndre opened this issue Aug 26, 2022 · 0 comments · Fixed by #382
Closed

Support __halt_compiler as a member of the top level statements #381

TysonAndre opened this issue Aug 26, 2022 · 0 comments · Fixed by #382

Comments

@TysonAndre
Copy link
Contributor

TysonAndre commented Aug 26, 2022

This would allow validation test suites to pass again

  • On the top level scope, emit a new HaltCompilerStatement with haltCompilerToken, openParen, closeParen, semicolonToken, and data of type T_INLINE_HTML
  • It's a compile error on an inner statement, so not really important to parse it, but that would be with a MissingToken for data if it was parsed in an inner statement.
// Zend/zend_language_parser.y
top_statement:
//  ....
	|	T_HALT_COMPILER '(' ')' ';'
			{ $$ = zend_ast_create(ZEND_AST_HALT_COMPILER,
			      zend_ast_create_zval_from_long(zend_get_scanned_file_offset()));
			  zend_stop_lexing(); }
php > var_export(token_get_all('<?php echo 2; __halt_compiler(); ?><?php fake data'));
array (
  0 => 
  array (
    0 => 382,
    1 => '<?php ',
    2 => 1,
  ),
  1 => 
  array (
    0 => 324,
    1 => 'echo',
    2 => 1,
  ),
  2 => 
  array (
    0 => 385,
    1 => ' ',
    2 => 1,
  ),
  3 => 
  array (
    0 => 309,
    1 => '2',
    2 => 1,
  ),
  4 => ';',
  5 => 
  array (
    0 => 385,
    1 => ' ',
    2 => 1,
  ),
  6 => 
  array (
    0 => 363,
    1 => '__halt_compiler',
    2 => 1,
  ),
  7 => '(',
  8 => ')',
  9 => ';',
  10 => 
  array (
    0 => 313,
    1 => ' ?><?php fake data',
    2 => 1,
  ),
)
php > echo token_name(313);
T_INLINE_HTML
TysonAndre added a commit to TysonAndre/tolerant-php-parser that referenced this issue Aug 27, 2022
https://www.php.net/manual/en/function.halt-compiler.php can be used to
embed data in php scripts from the outermost scope.
In inner scope, it is parsed in php-src only for the sake of error
messages about it needing to be in the outermost scope, so treat it as
an unexpected token in other contexts.

Closes microsoft#381
TysonAndre added a commit to TysonAndre/tolerant-php-parser that referenced this issue Aug 27, 2022
https://www.php.net/manual/en/function.halt-compiler.php can be used to
embed data in php scripts from the outermost scope.
In inner scope, it is parsed in php-src only for the sake of error
messages about it needing to be in the outermost scope, so treat it as
an unexpected token in other contexts.

(In an inner `{...}` scope, the call to `token_get_all()` will still
stop after `__halt_compiler();`, returning T_INLINE_HTML,
so the remaining statements can't be parsed, anyway)

Additionally, `__halt_compiler` can't be used as a name, a member name
(e.g. method name), etc, so calling it `TokenKind::Name` seems
incorrect. (`__COMPILER_HALT_OFFSET__` is already properly a Name)

Closes microsoft#381
TysonAndre added a commit to TysonAndre/tolerant-php-parser that referenced this issue Sep 25, 2022
Make it easier to calculate `__COMPILER_HALT_OFFSET__`.
Related to microsoft#381
TysonAndre added a commit to TysonAndre/tolerant-php-parser that referenced this issue Sep 25, 2022
Make it easier to calculate `__COMPILER_HALT_OFFSET__`.
Related to microsoft#381
TysonAndre added a commit to TysonAndre/tolerant-php-parser that referenced this issue Sep 25, 2022
Make it easier to calculate `__COMPILER_HALT_OFFSET__`.
Related to microsoft#381

Address other edge cases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant