rectorphp/rector · error · InvalidConfigurationException

Parameter "%s::%s" must be int, "%s" given.%sUse constant fr

Error message

Parameter "%s::%s" must be int, "%s" given.%sUse constant from "%s" to provide it, e.g. "%s::%s"

What it means

PhpVersionProvider validates the PHP_VERSION_FEATURES option (the --php-features CLI value / Option::PHP_VERSION_FEATURES parameter). The value must be an integer matching the version regex AND be at least PhpVersion::PHP_53 - 1; anything else (string versions, floats, out-of-range ints) is routed to throwInvalidTypeException(), which names the option, echoes the received value, and points at the PhpVersion constants.

Source

Thrown at src/Php/PhpVersionProvider.php:88

        if (in_array($phpVersionFeatures, $phpVersionReflectionClass->getConstants(), \true)) {
            return;
        }
        if (!is_int($phpVersionFeatures)) {
            $this->throwInvalidTypeException($phpVersionFeatures);
        }
        if (StringUtils::isMatch((string) $phpVersionFeatures, self::VALID_PHP_VERSION_REGEX) && $phpVersionFeatures >= PhpVersion::PHP_53 - 1) {
            return;
        }
        $this->throwInvalidTypeException($phpVersionFeatures);
    }
    /**
     * @return never
     * @param mixed $phpVersionFeatures
     */
    private function throwInvalidTypeException($phpVersionFeatures)
    {
        $errorMessage = sprintf('Parameter "%s::%s" must be int, "%s" given.%sUse constant from "%s" to provide it, e.g. "%s::%s"', Option::class, 'PHP_VERSION_FEATURES', (string) $phpVersionFeatures, \PHP_EOL, PhpVersion::class, PhpVersion::class, 'PHP_80');
        throw new InvalidConfigurationException($errorMessage);
    }
}

View on GitHub (pinned to 408fcb0ff1)

Solutions

  1. Pass a PhpVersion constant int: \Rector\ValueObject\PhpVersion::PHP_81
  2. If the value comes from config, cast/validate it first: is_int($v) && $v >= PhpVersion::PHP_53
  3. Echo the received value shown in the message ('"8.1" given') to spot the type leak in your pipeline

Example fix

// before
$parameters = [
    Option::PHP_VERSION_FEATURES => '8.1',
];

// after
use Rector\ValueObject\PhpVersion;

$parameters = [
    Option::PHP_VERSION_FEATURES => PhpVersion::PHP_81,
];
Defensive patterns

Strategy: type-guard

Type guard

/** @param mixed $value */
function isPhpVersionFeaturesValue($value): bool
{
    return is_int($value) && $value >= \Rector\ValueObject\PhpVersion::PHP_53 - 1;
}

Prevention

When it happens

Trigger: Passing '8.1' or 8.1 (string/float) to --php-features; passing an int below PHP_53 - 1 such as 42; constructing the option array with ['php_version_features' => '80100'] from untyped config.

Common situations: YAML/CLI config reading the version from an env var that arrives as a string; glue code mapping a composer constraint like '^8.1' directly to the option; copy-pasting 8010 (dropped digit).

Related errors


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