Implement token-aware PHP transformer with type declaration preservation#3
Merged
archisgore merged 1 commit intomainfrom Jan 25, 2026
Merged
Implement token-aware PHP transformer with type declaration preservation#3archisgore merged 1 commit intomainfrom
archisgore merged 1 commit intomainfrom
Conversation
This transformer uses PHP's built-in tokenizer to properly parse PHP code and preserve type declarations while transforming keywords and operators. Key Features: - Uses token_get_all() for accurate PHP parsing - Tracks context (parameter lists, return types, property types) - Preserves all PHP type names in type declarations - Handles PHP 7.4+ and 8.0+ type features - Special handling for T_STATIC token Files Added: - token-aware-transformer.php: Main transformer implementation - snip-transform-v2.php: Updated snip-transform with type awareness - transform-php-file-v2.php: Standalone file transformer - README-token-aware.md: Comprehensive documentation - Test files for validation This solves the fatal error issue where type names were being scrambled: Cannot use int as default value for parameter of type ?XYZ Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR implements a token-aware PHP transformer that properly preserves PHP type declarations, replacing the simple text-replacement approach that was incorrectly transforming type names.
Key Features
✅ Type-Aware: Preserves PHP type names (int, string, bool, float, etc.) in type declarations
✅ Context-Sensitive: Understands when keywords are used as types vs. code
✅ Grammar-Correct: Uses PHP's
token_get_all()for accurate parsing✅ Comprehensive: Handles all PHP 7.4+ type declaration features including:
What Gets Preserved
int,float,string,boolarray,object,callable,iterablevoid,mixed,never,null,false,trueself,parent,staticCritical Bug Fix
Fixed handling of the
statickeyword which tokenizes asT_STATIC(notT_STRING). The transformer now correctly preservesstaticin type contexts while still transforming it as a keyword elsewhere.Implementation
The transformer uses:
token_get_all()for proper PHP parsingFiles Added
encrypted-execution/tools/scrambler/token-aware-transformer.php- Main transformer implementationencrypted-execution/tools/scrambler/README-token-aware.md- Documentationencrypted-execution/tools/scrambler/test-type-declarations.php- Comprehensive test suiteencrypted-execution/tools/scrambler/test-dictionary.json- Test dictionaryTesting
Comprehensive tests validate:
Example
This fixes the root cause of the WordPress PR failures where type names were being scrambled, causing PHP parse errors.
🤖 Generated with Claude Code