Proposal: Support overriding short_open_tag in token_get_all() #9612
+65
−9
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.
Details
Add the flags TOKEN_ENABLE_SHORT_OPEN_TAG/TOKEN_DISABLE_SHORT_OPEN_TAG to
token_get_all
andPhpToken::tokenize()
If both flags are accidentally combined,
TOKEN_DISABLE_SHORT_OPEN_TAG takes precedence.
If neither bit flag is provided, then token_get_all continues to use the value of the system ini setting
short_open_tag
Motivation
<?php
tags in migration scriptsImplementation details
When preparing to scan tokens from a string (or from a file), this copies constant
CG(short_tags)
corresponding to the system ini settingshort_open_tags
toSCNG(short_tags)
(scanner globals).PHP modules such as
tokenizer
can then conditionally override it after the call tozend_prepare_string_for_scanning
(PECLs can also make use of this safely starting)To handle edge cases such as compilation triggering an error handler which calls token_get_all, zend_save_lexical_state and zend_restore_lexical_state also save/restore
short_tags
Other Notes
This deliberately does not deprecate short open tags or change default settings and that is not planned. A previous RFC by another developer aimed to deprecate short open tags entirely but that did not go through.