Skip to content

PHP 7.4 | Tokenizer/PHP: handle PHP tag at end of file consistently #937

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

Merged
merged 1 commit into from
Apr 9, 2025

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Apr 6, 2025

Description

Prior to PHP 7.4, a PHP open tag at the end of a file was not tokenized correctly in PHP itself.

From the PHP 7.4 changelog:

<?php at the end of the file (without trailing newline) will now be
interpreted as an opening PHP tag. Previously it was interpreted either as
<? php and resulted in a syntax error (with short_open_tag=1) or was
interpreted as a literal <?php string (with short_open_tag=0).

This commit makes the tokenization of PHP open tags at the end of a file consistent in all PHP versions.

Includes tests.
Includes adding a few extra test builds which test with short_open_tag=On for various PHP versions.

Refs:

Suggested changelog entry

Tokenizer/PHP: a PHP open tag at the very end of a file will now always be tokenized as T_OPEN_TAG, independently of the PHP version.

Prior to PHP 7.4, a PHP open tag at the end of a file was not tokenized correctly in PHP itself.

From the PHP 7.4 changelog:
> `<?php` at the end of the file (without trailing newline) will now be
> interpreted as an opening PHP tag. Previously it was interpreted either as
> `<? php` and resulted in a syntax error (with short_open_tag=1) or was
> interpreted as a literal `<?php` string (with short_open_tag=0).

This commit makes the tokenization of PHP open tags at the end of a file consistent in all PHP versions.

Includes tests.
Includes adding a few extra test builds which test with `short_open_tag=On` for various PHP versions.

Refs:
* https://www.php.net/manual/en/migration74.incompatible.php#migration74.incompatible.core.php-tag
* https://github.com/php/php-src/blob/30de357fa14480468132bbc22a272aeb91789ba8/UPGRADING#L37-L40
@jrfnl jrfnl added this to the 3.12.2 milestone Apr 6, 2025
@jrfnl jrfnl merged commit 7a1c8b9 into master Apr 9, 2025
275 of 316 checks passed
@jrfnl jrfnl deleted the feature/tokenizer-php-open-tag-end-of-file branch April 9, 2025 04:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant