rectorphp/rector · error · InvalidConfigurationException

The "->withPhpSets()" method uses named arguments. Its suita

Error message

The "->withPhpSets()" method uses named arguments. Its suitable for PHP 8.0+. Use "->withPhpLevel()" in lower PHP versions instead.

What it means

withPhpSets() uses PHP 8.0 named arguments (php82: true), which cannot even be parsed by PHP 7.x. When Rector itself runs under PHP_VERSION_ID < 80000, Notifier::errorWithPhpSetsNotSuitableForPHP74AndLower() throws InvalidConfigurationException and directs you to withPhpLevel(), whose positional int argument works on every PHP version.

Source

Thrown at src/Console/Notifier.php:27

use RectorPrefix202608\Symfony\Component\Console\Style\SymfonyStyle;
final class Notifier
{
    public static function notifyNotSuitableMethodForPHP74(string $calledMethod): void
    {
        if (\PHP_VERSION_ID >= 80000) {
            return;
        }
        $message = sprintf('The "%s()" method uses named arguments. Its suitable for PHP 8.0+. In lower PHP versions, use "withSets([...])" method instead', $calledMethod);
        $symfonyStyle = new SymfonyStyle(new ArgvInput(), new ConsoleOutput());
        $symfonyStyle->warning($message);
        sleep(3);
    }
    public static function errorWithPhpSetsNotSuitableForPHP74AndLower(): void
    {
        if (\PHP_VERSION_ID >= 80000) {
            return;
        }
        throw new InvalidConfigurationException('The "->withPhpSets()" method uses named arguments. Its suitable for PHP 8.0+. Use "->withPhpLevel()" in lower PHP versions instead.');
    }
}

View on GitHub (pinned to 408fcb0ff1)

Solutions

  1. Replace withPhpSets(...) with withPhpLevel(\Rector\ValueObject\PhpVersion::PHP_74) — a plain int argument valid on all PHP versions
  2. Or execute Rector with a PHP 8+ binary while keeping the downgrade target: php8.1 vendor/bin/rector process
  3. If staying on the old API, use withSets([LevelSetList::UP_TO_PHP_74]) with an explicit import

Example fix

// before
return RectorConfig::configure()
    ->withPhpSets(php74: true);

// after
use Rector\ValueObject\PhpVersion;

return RectorConfig::configure()
    ->withPhpLevel(PhpVersion::PHP_74);
Defensive patterns

Strategy: validation

Validate before calling

// choose API by interpreter, before loading rector.php
if (PHP_VERSION_ID < 80000) {
    // positional int works everywhere
    $configurator->withPhpLevel(\Rector\ValueObject\PhpVersion::PHP_74);
} else {
    $configurator->withPhpSets(php74: true);
}

Prevention

When it happens

Trigger: A rector.php containing ->withPhpSets(php74: true) (or the no-argument form) executed by a PHP 7.4 interpreter, e.g. vendor/bin/rector resolved to a PHP 7.4 binary via composer config platform or a CI image pinned to 7.4.

Common situations: Legacy project pinned to PHP 7.4 where composer runs scripts with the project interpreter; developer's default php on PATH is old; CI matrix reuses a 7.4 job to run Rector for a still-supported branch.

Related errors


AI-assisted analysis of rectorphp/rector@408fcb0ff1 (2026-08-21). Data as JSON: /api/errors/bc95714b041e2e90. Report an issue: GitHub.