{"record":{"id":"de63247ae2ad2f07","repo":"symfony/css-selector","slug":"function-s-not-supported","errorCode":null,"errorMessage":"Function \"%s\" not supported.","messagePattern":"Function \"(.+?)\" not supported\\.","errorType":"exception","errorClass":"ExpressionErrorException","httpStatus":null,"severity":"error","filePath":"XPath/Translator.php","lineNumber":193,"sourceCode":"    /**\n     * @throws ExpressionErrorException\n     */\n    public function addRelativeCombination(string $combiner, NodeInterface $xpath, NodeInterface $combinedXpath): XPathExpr\n    {\n        if (!isset($this->relativeCombinationTranslators[$combiner])) {\n            throw new ExpressionErrorException(\\sprintf('Combiner \"%s\" not supported.', $combiner));\n        }\n\n        return $this->relativeCombinationTranslators[$combiner]($this->nodeToXPath($xpath), $this->nodeToXPath($combinedXpath));\n    }\n\n    /**\n     * @throws ExpressionErrorException\n     */\n    public function addFunction(XPathExpr $xpath, FunctionNode $function): XPathExpr\n    {\n        if (!isset($this->functionTranslators[$function->getName()])) {\n            throw new ExpressionErrorException(\\sprintf('Function \"%s\" not supported.', $function->getName()));\n        }\n\n        return $this->functionTranslators[$function->getName()]($xpath, $function);\n    }\n\n    /**\n     * @throws ExpressionErrorException\n     */\n    public function addPseudoClass(XPathExpr $xpath, string $pseudoClass): XPathExpr\n    {\n        if (!isset($this->pseudoClassTranslators[$pseudoClass])) {\n            throw new ExpressionErrorException(\\sprintf('Pseudo-class \"%s\" not supported.', $pseudoClass));\n        }\n\n        return $this->pseudoClassTranslators[$pseudoClass]($xpath);\n    }\n\n    /**","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/symfony/css-selector/blob/08e2905152a39cf3fd1745d83f8c483e258887d9/XPath/Translator.php#L175-L211","documentation":"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.","triggerScenarios":"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.","commonSituations":"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().","solutions":["Use only functions the library supports (:nth-child, :nth-last-child, :not, :lang, etc.) or rewrite the selector.","Register a custom function translator via an extension: $translator->extension(new MyFunctionExtension()).","Fix the selector spelling or upgrade Symfony to a version that supports the function."],"exampleFix":"// before\n$css = 'div:has(> p)'; // function not supported, throws\n\n// after\n$css = 'div > p'; // express the intent with supported selectors","handlingStrategy":"try-catch","validationCode":"$supported = ['nth-child','nth-last-child','nth-of-type','nth-last-of-type','not','lang','is','where'];\nif (!preg_match('/:([a-zA-Z-]+)\\s*\\(/', $css, $m) || !in_array($m[1], $supported, true)) {\n    throw new \\InvalidArgumentException('Unsupported selector function');\n}","typeGuard":"function usesOnlySupportedFunctions(string $css, array $supported): bool {\n    preg_match_all('/:([a-zA-Z-]+)\\s*\\(/', $css, $m);\n    return empty(array_diff($m[1], $supported));\n}","tryCatchPattern":"use Symfony\\Component\\CssSelector\\Exception\\ExpressionErrorException;\ntry {\n    $xpath = $translator->cssToXPath($css);\n} catch (ExpressionErrorException $e) {\n    // rewrite selector without the unsupported function or skip\n}","preventionTips":["Keep a whitelist of supported functional pseudo-classes for your Symfony version","Rewrite modern functions (:has, :is) into supported equivalents before translating","Add regression tests for every selector expression your app accepts"],"tags":["css-selector","xpath","selector-function","unsupported-function"],"backgroundTag":"unsupported-enum-value","analyzedSha":"08e2905152a39cf3fd1745d83f8c483e258887d9","analyzedAt":"2026-09-14T11:41:28.509Z","contentChangedAt":"2026-09-14T11:41:28.509Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}