Skip to content

Lazy-load retargeted rule class aliases - #8845

Merged
TomasVotruba merged 1 commit into
mainfrom
tv-lazy-rule-class-aliases
Oct 26, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
tv-lazy-rule-class-aliases

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

The src/functions/rule_class_aliases.php bootstrap (a composer files autoload entry) eagerly called class_alias(NewClass::class, OldFqn), which autoloads the retargeted rule classes on every bootstrap.

The scoped build lints the output under PHP 7.4. There, loading those classes hits their PHP 8 promoted private readonly constructor props and fails:

PHP Parse error: syntax error, unexpected 'private' (T_PRIVATE) in rules/Visibility/Rector/Class_/ChangeMethodVisibilityRector.php on line 30

so build_scoped_rector failed.

Register the legacy names via spl_autoload_register instead, aliasing to the current class only when the old FQN is actually requested. Nothing loads at bootstrap, so the 7.4 lint no longer parses PHP 8 rule classes.

rule_class_aliases.php is added to the existing "internal functions" group in phpstan.neon next to the sibling node_helper.php, as spl_autoload_register is otherwise forbidden.

@TomasVotruba
TomasVotruba merged commit 2c5dcce into main Oct 26, 2026
48 of 49 checks passed
@TomasVotruba
TomasVotruba deleted the tv-lazy-rule-class-aliases branch October 26, 2026 10:10
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.

1 participant