Skip to content

Define PHP 7.4 token constants for downgraded build - #126

Merged
TomasVotruba merged 1 commit into
mainfrom
polyfill-php72-token-constants
Jun 2, 2026
Merged

Define PHP 7.4 token constants for downgraded build#126
TomasVotruba merged 1 commit into
mainfrom
polyfill-php72-token-constants

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Problem

The released tool is downgraded to PHP 7.2, but the bundled nikic/php-parser references PHP 7.4 token constants directly. On a real 7.2 runtime this fatals on boot:

PHP Fatal error: Uncaught Error: Undefined constant 'T_BAD_CHARACTER'
  in vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php:155

(plus constant(): Couldn't find constant T_FN / T_COALESCE_EQUAL warnings)

php-parser ships compatibility_tokens.php, but it only polyfills PHP 8.0+ tokens — the 7.4 ones (T_FN, T_COALESCE_EQUAL, T_BAD_CHARACTER) are assumed to always exist, which is not true once the tool is downgraded to 7.2.

Fix

Define the three missing 7.4 token constants in the bin entry point, guarded by defined() so it is a no-op on PHP 7.4+. Same approach ECS uses in bin/ecs.php.

Verification

Ran the patched build on a real PHP 7.2.34 against a project — previously fatal, now:

[OK] No conflicts found in 17130 files

@TomasVotruba
TomasVotruba merged commit 4f39fea into main Jun 2, 2026
8 checks passed
@TomasVotruba
TomasVotruba deleted the polyfill-php72-token-constants branch June 2, 2026 09:37
@TomasVotruba

Copy link
Copy Markdown
Member Author

LGTM, let's ship

@TomasVotruba

TomasVotruba commented Jun 2, 2026

Copy link
Copy Markdown
Member Author

Comment thread bin/swiss-knife.php
Comment on lines +33 to +41
if (! defined('T_FN')) {
define('T_FN', 5025);
}
if (! defined('T_COALESCE_EQUAL')) {
define('T_COALESCE_EQUAL', 5030);
}
if (! defined('T_BAD_CHARACTER')) {
define('T_BAD_CHARACTER', 5035);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo, this should be equal with php 8.+ values:

php > echo T_FN;
311
php > echo T_COALESCE_EQUAL;
367
php > echo T_BAD_CHARACTER;
409

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't really matter, as it's a placeholder value. If it's not existing token value.

5xxx are reserved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants