symfony/css-selector · error · ExpressionErrorException

Function " " not supported.

Error message

Function "%s" not supported.

What it means

Translator::addFunction() looks up a functional pseudo-class name (e.g. 'nth-child', 'not', 'lang') in $this->functionTranslators and throws ExpressionErrorException when the function name has no registered translator. This guards the extension point so unknown selector functions fail loudly rather than generating invalid XPath.

Solutions

  1. Use only functions the library supports (:nth-child, :nth-last-child, :not, :lang, etc.) or rewrite the selector.
  2. Register a custom function translator via an extension: $translator->extension(new MyFunctionExtension()).
  3. Fix the selector spelling or upgrade Symfony to a version that supports the function.

Example fix

// before
$css = 'div:has(> p)'; // function not supported, throws

// after
$css = 'div > p'; // express the intent with supported selectors
Defensive patterns

Strategy: try-catch

Validate before calling

$supported = ['nth-child','nth-last-child','nth-of-type','nth-last-of-type','not','lang','is','where'];
if (!preg_match('/:([a-zA-Z-]+)\s*\(/', $css, $m) || !in_array($m[1], $supported, true)) {
    throw new \InvalidArgumentException('Unsupported selector function');
}

Type guard

function usesOnlySupportedFunctions(string $css, array $supported): bool {
    preg_match_all('/:([a-zA-Z-]+)\s*\(/', $css, $m);
    return empty(array_diff($m[1], $supported));
}

Try / catch

use Symfony\Component\CssSelector\Exception\ExpressionErrorException;
try {
    $xpath = $translator->cssToXPath($css);
} catch (ExpressionErrorException $e) {
    // rewrite selector without the unsupported function or skip
}

Prevention

When it happens

Trigger: Calling addFunction() with a FunctionNode whose getName() is not a key in functionTranslators — e.g. translating a selector using an unsupported CSS function like :is() in an older Symfony version, or a custom :my-func() without a registered handler.

Common situations: Using modern CSS functions (:is, :where, :has) not supported by the bundled CssSelector version; custom function extensions not registered via Translator::extension(); typos in selector strings like :nth-of-typee().

Related errors


AI-assisted analysis of symfony/css-selector@08e2905152 (2026-09-14). Data as JSON: /api/errors/de63247ae2ad2f07. Report an issue: GitHub.

Appendix: source

Thrown at XPath/Translator.php:193

    /**
     * @throws ExpressionErrorException
     */
    public function addRelativeCombination(string $combiner, NodeInterface $xpath, NodeInterface $combinedXpath): XPathExpr
    {
        if (!isset($this->relativeCombinationTranslators[$combiner])) {
            throw new ExpressionErrorException(\sprintf('Combiner "%s" not supported.', $combiner));
        }

        return $this->relativeCombinationTranslators[$combiner]($this->nodeToXPath($xpath), $this->nodeToXPath($combinedXpath));
    }

    /**
     * @throws ExpressionErrorException
     */
    public function addFunction(XPathExpr $xpath, FunctionNode $function): XPathExpr
    {
        if (!isset($this->functionTranslators[$function->getName()])) {
            throw new ExpressionErrorException(\sprintf('Function "%s" not supported.', $function->getName()));
        }

        return $this->functionTranslators[$function->getName()]($xpath, $function);
    }

    /**
     * @throws ExpressionErrorException
     */
    public function addPseudoClass(XPathExpr $xpath, string $pseudoClass): XPathExpr
    {
        if (!isset($this->pseudoClassTranslators[$pseudoClass])) {
            throw new ExpressionErrorException(\sprintf('Pseudo-class "%s" not supported.', $pseudoClass));
        }

        return $this->pseudoClassTranslators[$pseudoClass]($xpath);
    }

    /**

View on GitHub (pinned to 08e2905152)