Repository navigation
Skip PhpParser\NodeTraverser in preload.php when it is already declared - #8689
Merged
TomasVotruba merged 1 commit intoOct 18, 2026
Merged
Conversation
PHPStan Turbo declares a native PhpParser\NodeTraverser when it is activated. preload.php then fails with "Cannot redeclare class". Without Turbo, the class is not declared yet and preload.php loads it as before.
staabm
approved these changes
Oct 18, 2026
Member
|
Thank you, can't wait to test this one 👍 |
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.
PHPStan Turbo declares a native
PhpParser\NodeTraverserwhen it is activated. Rector has to activate it beforepreload.phpruns, because Turbo cannot replace a class that is already declared. The plainrequire_onceof php-parser'sNodeTraverser.phpinpreload.phpthen fails with "Cannot redeclare class PhpParser\NodeTraverser".build/build-preload.phpnow wraps that one line inif (! class_exists(NodeTraverser::class, false)), the same way the template already checksPHPStanTestCase.preload.phpis regenerated withcomposer preload. Without Turbo the class is not declared yet, sopreload.phploads it as before.This prepares for loading Turbo in
bin/rector.php. That part needs PHPStan 2.3.2, for phpstan/phpstan-src#6720. A proof of concept is on https://github.com/SanderMuller/rector-src/tree/turbo-poc.I ran a cold
bin/rector process --dry-run --clear-cacheon rector-src itself, with 14 workers. It takes 8.2 s instead of 11.6 s, and 61 s of CPU instead of 100 s. Those are medians of 5 runs on an M4 Pro with PHP 8.5. The output is the same in all runs.