{"record":{"id":"f688b372b33d185f","repo":"symfony/routing","slug":"the-return-value-in-config-file-s-is-expected-to-be-a","errorCode":null,"errorMessage":"The return value in config file \"%s\" is expected to be a RouteCollection, an array or a configurator callable, but got \"%s\".","messagePattern":"The return value in config file \"(.+?)\" is expected to be a RouteCollection, an array or a configurator callable, but got \"(.+?)\"\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"Loader/PhpFileLoader.php","lineNumber":64,"sourceCode":"        }\n\n        // the closure forbids access to the private scope in the included file\n        $loader = $this;\n        $load = \\Closure::bind(static function ($file) use ($loader) {\n            return include $file;\n        }, null, null);\n\n        if (1 === $result = $load($path)) {\n            $result = null;\n        }\n\n        if (\\is_object($result) && \\is_callable($result)) {\n            $collection = $this->callConfigurator($result, $path, $file);\n        } elseif (\\is_array($result)) {\n            $collection = new RouteCollection();\n            $this->loadContent($collection, $result, $path, $file);\n        } elseif (!($collection = $result) instanceof RouteCollection) {\n            throw new InvalidArgumentException(\\sprintf('The return value in config file \"%s\" is expected to be a RouteCollection, an array or a configurator callable, but got \"%s\".', $path, get_debug_type($result)));\n        }\n\n        $collection->addResource(new FileResource($path));\n\n        return $collection;\n    }\n\n    public function supports(mixed $resource, ?string $type = null): bool\n    {\n        return \\is_string($resource) && 'php' === pathinfo($resource, \\PATHINFO_EXTENSION) && (!$type || 'php' === $type);\n    }\n\n    /**\n     * @param-immediately-invoked-callable $callback\n     */\n    protected function callConfigurator(callable $callback, string $path, string $file): RouteCollection\n    {\n        $collection = new RouteCollection();","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/symfony/routing/blob/83fa223250b50f4f018c011e101c330e65ac63cc/Loader/PhpFileLoader.php#L46-L82","documentation":"PhpFileLoader expects a route config PHP file to return a RouteCollection, an array of route definitions, or an invokable configurator object. Any other return value triggers this InvalidArgumentException, telling you the actual type returned via get_debug_type().","triggerScenarios":"A config/routes/*.php file whose return statement yields e.g. a string, null, true/false, or an unrelated object (non-callable), while loading routes through PhpFileLoader.","commonSituations":"Hand-writing route PHP files and forgetting the return statement (returns null); returning a builder object instead of the collection; migrating YAML routes and mixing in plain values.","solutions":["Make the config file return one of: a RouteCollection, an array (with ->setDefault etc. or nested route arrays), or an invokable configurator.","If returning null, add the missing return statement.","Check with get_debug_type in the message what type was actually returned and correct it."],"exampleFix":"// before\n<?php // config/routes/x.php\n$collection = new RouteCollection(); $collection->add(...);\n// (no return -> null)\n// after\n<?php\n$collection = new RouteCollection(); $collection->add(...);\nreturn $collection;","handlingStrategy":"validation","validationCode":"$result = require $path;\nif (!$result instanceof RouteCollection && !is_array($result) && !(is_object($result) && is_callable($result))) {\n  throw new \\InvalidArgumentException(sprintf('%s must return RouteCollection|array|callable, got %s', $path, get_debug_type($result)));\n}","typeGuard":null,"tryCatchPattern":"try { $collection = $phpLoader->load($path); } catch (\\InvalidArgumentException $e) { if (str_contains($e->getMessage(), 'expected to be a RouteCollection')) { throw new \\RuntimeException(\"Bad route config file: $path\", 0, $e); } throw $e; }","preventionTips":["Always end route config PHP files with an explicit return.","Return RouteCollection, a plain route array, or an invokable configurator — nothing else.","Lint route config files in CI by loading them with PhpFileLoader."],"tags":["symfony","routing","php-config"],"backgroundTag":"config-type-mismatch","analyzedSha":"83fa223250b50f4f018c011e101c330e65ac63cc","analyzedAt":"2026-09-14T03:19:46.280Z","contentChangedAt":"2026-09-14T03:19:46.280Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}