Rector 2.9 landed on 24 November 2026, followed the same night by patch releases 2.9.1 and 2.9.2. It’s a cleanup release. About 100 long-deprecated rules are gone, more than 30 rules now refuse to make changes that could alter behaviour, and a few new refactorings were added. If you run Rector in CI or use it for PHP version upgrades, here’s what to change and how to upgrade safely.
Install the latest 2.9.x
composer require --dev rector/rector:^2.9
vendor/bin/rector --version
Make sure you end up on 2.9.2 or later. The reason is explained below.
1. About 100 deprecated rules were removed
From the Rector 2.9.0 release notes: rules deprecated in 2.8 are now removed. They already threw an exception when used, weren’t part of any set, and were rarely used. The removals cover Arguments, CodeQuality, CodingStyle, DeadCode, EarlyReturn, Naming, the Php70–Php85 groups, Renaming, Strict, Transform, TypeDeclaration and more.
Also removed:
- The deprecated
SetList::PHP_*,SetList::NAMING,SetList::EARLY_RETURN,SetList::INSTANCEOFandSetList::IFconstants withSetProviders()in the configuration- The
githubandgitlaboutput formats
What to do: run Rector once after upgrading. If your rector.php still registers a removed rule or constant, you’ll get an error naming it. Delete that line. If you used the github or gitlab output format in CI, switch to another supported format.
2. Move from LevelSetList to withPhpSets()
LevelSetList is now deprecated in favour of withPhpSets() and withPhpLevel(). A modern config looks like this:
<?php
declare(strict_types=1);
use Rector\Config\RectorConfig;
return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
])
// Reads your PHP version from composer.json "require.php"
->withPhpSets()
->withPreparedSets(
deadCode: true,
codeQuality: true,
)
->withImportNames(removeUnusedImports: true);
If you had something like ->withSets([LevelSetList::UP_TO_PHP_83]), replace it with ->withPhpSets() and let Rector read the target version from composer.json. Use withPhpLevel() when you want to apply PHP rules gradually, a few at a time.
Other deprecations in 2.9:
RenameStringRector(replaced by dedicated rules)StaticCallToNewRector,WrapReturnRectorandAttributeKeyToClassConstFetchRectorFuncCallToConstFetchRector(and thephp_sapi_name()/pi()to constant conversion was dropped)NewlineAfterStatementRector, since the release notes say it fits better in a coding standard tool
Deprecated rules still work in 2.9, but they’ll follow the same path as the ones just removed, so plan to drop them.
3. Safer rules: Rector now leaves risky code alone
The release says more than 30 rules now skip code where a change could alter behaviour, such as side effects, evaluation order, loose comparisons, fall-through cases and nullable types. Some examples from the notes:
RemoveUnusedPrivatePropertyRectorkeeps side effects of the assigned value.RemoveDeadStmtRectorkeeps the evaluation order of side effects and keepsclonestatements.RemoveDeadLoopRectorkeeps loops whose condition changes state.RemoveDuplicatedCaseInSwitchRectorskips cases reached by fall-through.SingularSwitchToIfRectorkeeps loose comparison, sinceswitchcompares with==.MinMaxToClampRector(PHP 8.6 set) folds toclamp()only whenmin <= maxis proven.ChangeSwitchToMatchRectorskips an int cast of a string subject.
What this means for you: after upgrading, Rector may make fewer changes on the same codebase. That’s intended. If a CI job asserts “Rector finds nothing to change”, it will keep passing. If you’re mid-migration, you might see a few spots Rector used to rewrite and now leaves for you to review by hand.
4. New refactorings worth knowing
PHP 8.4: new without parentheses, in more places. NewMethodCallWithoutParenthesesRector now handles property fetch, static access, array access and invocation:
// Before
$message = (new Regex('some-pattern'))->message;
$constant = (new Request())::METHOD_GET;
$value = (new ArrayObject($items))['key'];
// After (PHP 8.4+)
$message = new Regex('some-pattern')->message;
$constant = new Request()::METHOD_GET;
$value = new ArrayObject($items)['key'];
Partial list() destructuring is converted by ListToArrayDestructRector:
// Before
list(, $instanceId) = explode(':', $rate->id);
// After
[, $instanceId] = explode(':', $rate->id);
void on final methods of non-final classes via AddVoidReturnTypeWhereNoReturnRector, and an object return type for (object) casts in ReturnTypeFromReturnCastRector:
// Before
public function run($data): \stdClass
{
return (object) $data;
}
// After
public function run($data): object
{
return (object) $data;
}
Simpler negated ternaries in UnnecessaryTernaryExpressionRector: return $order ? false : true; becomes return !$order;.
Better skip reporting: ->reportUnusedSkips() now works in the default parallel run, not only with --debug or withoutParallel(). Turn it on to clean up skips that no longer match anything:
return RectorConfig::configure()
->withPaths([__DIR__ . '/src'])
->withSkip([
\Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector::class => [
__DIR__ . '/src/Legacy',
],
])
->reportUnusedSkips();
5. Why you want 2.9.2, not 2.9.0
Rector 2.9.0 introduced NarrowPreviousExceptionCodeArgRector, which rewrote new RuntimeException('ups', $e->getCode(), $e) to use only previous: $e. The 2.9.2 release removed that rule because it changes behaviour. PHP doesn’t inherit the code from the previous exception, so the new exception’s getCode() returns 0.
The rule was part of the named-args set and the code quality level in 2.9.0. If you ran 2.9.0 with those sets, search your diff for removed ->getCode() arguments before you merge:
git diff | grep -n "getCode()"
If you registered the rule manually, remove it from your config.
A safe upgrade routine
- Upgrade on a branch:
composer require --dev rector/rector:^2.9. - Run a dry run first:
vendor/bin/rector process --dry-run. - Fix config errors about removed rules or constants.
- Replace
LevelSetListwithwithPhpSets(). - Apply changes, then run your test suite and static analysis, such as PHPStan.
- Commit Rector’s changes separately from your own so reviews stay easy.
The ecosystem packages changed too. rector-symfony, rector-phpunit and rector-doctrine each removed their own deprecated rules and added a few new ones. If you use them, read their sections in the release notes.
Takeaway
Rector 2.9 is about trust. It ships fewer, more reliable rules and stops making changes that could quietly alter behaviour. Upgrade to 2.9.2 or later, delete removed rules from rector.php, move from LevelSetList to withPhpSets(), and check any 2.9.0 run for dropped exception codes.
