rectorphp/rector · error · InvalidEregException

an invalid or unsupported character class [%s]

Error message

an invalid or unsupported character class [%s]

What it means

processCharacterClass() recognized a POSIX bracket class '[[:...:]]' and looked the inner name up in CHARACTER_CLASS_MAP, which supports only alnum, alpha, blank, cntrl, digit, graph, lower, print, punct, space, upper, xdigit. The name was not found, so InvalidEregException('an invalid or unsupported character class [name]') is thrown (EregToPcreTransformer.php:290) and the ereg-to-preg conversion aborts.

Source

Thrown at rules/Php70/EregToPcreTransformer.php:290

            $r[$rr] .= '{' . $matches[self::MINIMAL_NUMBER_PART] . '}';
        }
        return $ii + 1;
    }
    /**
     * @return int[]|string[]
     */
    private function processCharacterClass(string $content, int $i, string $cls): array
    {
        $offset = $i;
        $ii = strpos($content, ']', $offset);
        if ($ii === \false) {
            throw new InvalidEregException('"[" does not have a matching "]"');
        }
        $start = $i + 1;
        $length = $ii - ($i + 1);
        $ccls = Strings::substring($content, $start, $length);
        if (!isset(self::CHARACTER_CLASS_MAP[$ccls])) {
            throw new InvalidEregException('an invalid or unsupported character class [' . $ccls . ']');
        }
        $cls .= self::CHARACTER_CLASS_MAP[$ccls];
        $i = $ii + 1;
        return [$cls, $i];
    }
}

View on GitHub (pinned to 408fcb0ff1)

Solutions

  1. Replace the unsupported class in the flagged pattern with a supported equivalent: '[[:word:]]' -> '[A-Za-z0-9_]'.
  2. Check the name against the supported list (alnum, alpha, blank, cntrl, digit, graph, lower, print, punct, space, upper, xdigit) and fix typos like '[[:diget:]]' -> '[[:digit:]]'.
  3. Re-run rector; preflight literal ereg patterns for '[[:...:]]' names not in that list.

Example fix

// before - unsupported class
ereg('[[:word:]]', $subject);

// after - supported equivalent
ereg('[[:alnum:]_]', $subject); // rector: preg_match('#[[:alnum:]_]#m', $subject)
Defensive patterns

Strategy: validation

Validate before calling

const SUPPORTED = ['alnum','alpha','blank','cntrl','digit','graph','lower','print','punct','space','upper','xdigit'];
if (preg_match_all('~\[\[:([a-z]+):\]~', $pattern, $m)) {
    foreach ($m[1] as $name) {
        if (!in_array($name, SUPPORTED, true)) {
            throw new InvalidArgumentException("unsupported POSIX class [[:{$name}:]]");
        }
    }
}

Try / catch

try {
    $pcre = $eregToPcreTransformer->transform($pattern, $ignoreCase);
} catch (InvalidEregException $e) {
    // class name not in the supported 13 — substitute an equivalent and re-run
    continue;
}

Prevention

When it happens

Trigger: Rector (Php70 set / EregToPregMatchRector, target PHP >= 7.0) processes an ereg-family call whose literal pattern uses a bracket class outside the supported list, e.g. `ereg('[[:word:]]', $s)` (word is a GNU extension, not mapped), `split('[[:foo:]]', $s)`, or typo'd names like '[[:diget:]]'. The isset() on CHARACTER_CLASS_MAP fails and the offending class name is embedded in the message.

Common situations: Patterns ported from GNU grep/sed that support extra classes ('[[:word:]]'); PCRE-style '\w' habits translated to a nonexistent '[[:word:]]'; typo'd class names inside old validation patterns for emails, zip codes, etc.

Related errors


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