symfony/routing · error · InvalidArgumentException

" :: " is not a case of " ".

Error message

"%s::%s" is not a case of "%s".

What it means

When EnumRequirement receives an array of enum cases, it verifies all cases belong to the same enum class; the first case's class is captured and any case that is not an instanceof it triggers this error. It also fires for typed mismatch between different enums in one array.

Solutions

  1. Ensure all cases in the array come from one enum class
  2. Pass the enum class-string instead of an array of cases
  3. Fix the dynamic case-list builder to only pull from the intended enum

Example fix

// before
$req = new EnumRequirement([Status::Active, OtherStatus::Pending]);
// after
$req = new EnumRequirement([Status::Active, Status::Inactive]);
Defensive patterns

Strategy: validation

Validate before calling

$classes = array_unique(array_map(fn($c) => $c::class, $cases));
if (count($classes) > 1) throw new \InvalidArgumentException('Cases must come from a single enum');

Type guard

function isSingleEnumCaseList(array $cases): bool {
    return $cases !== [] && count(array_unique(array_map(fn($c) => $c::class, $cases))) === 1;
}

Try / catch

try {
    $requirement = new EnumRequirement($cases);
} catch (\InvalidArgumentException $e) {
    // fall back to building the list from a single enum: EnumRequirement(Status::class)
}

Prevention

When it happens

Trigger: new EnumRequirement([Status::Active, OtherStatus::Pending]) mixing cases of two different enums, or a dynamically-built array that accidentally includes a case from another enum.

Common situations: Building a list of allowed cases programmatically from several enums, refactoring that renamed/moved cases, or copy-pasting case lists across enums.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of symfony/routing@83fa223250 (2026-09-14). Data as JSON: /api/errors/8510b7560c1cfbb7. Report an issue: GitHub.

Appendix: source

Thrown at Requirement/EnumRequirement.php:44

    {
        if (\is_string($cases)) {
            if (!is_subclass_of($cases, \BackedEnum::class, true)) {
                throw new InvalidArgumentException(\sprintf('"%s" is not a "BackedEnum" class.', $cases));
            }

            $cases = $cases::cases();
        } else {
            $class = null;

            foreach ($cases as $case) {
                if (!$case instanceof \BackedEnum) {
                    throw new InvalidArgumentException(\sprintf('Case must be a "BackedEnum" instance, "%s" given.', get_debug_type($case)));
                }

                $class ??= $case::class;

                if (!$case instanceof $class) {
                    throw new InvalidArgumentException(\sprintf('"%s::%s" is not a case of "%s".', get_debug_type($case), $case->name, $class));
                }
            }
        }

        $this->requirement = implode('|', array_map(static fn ($e) => preg_quote($e->value), $cases));
    }

    public function __toString(): string
    {
        return $this->requirement;
    }
}

View on GitHub (pinned to 83fa223250)