Skip to content

Conversation

TysonAndre
Copy link
Contributor

@TysonAndre TysonAndre commented 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 #381

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 TysonAndre force-pushed the halt-compiler-support branch from 9e352b2 to a036846 Compare August 27, 2022 12:42
@TysonAndre
Copy link
Contributor Author

@roblourens - this is ready for review

@TysonAndre
Copy link
Contributor Author

@roblourens - thoughts?

@roblourens roblourens merged commit ba1f1e8 into microsoft:main Sep 25, 2022
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 this pull request may close these issues.

Support __halt_compiler as a member of the top level statements
2 participants