{"record":{"id":"d5daaa324055458f","repo":"phalcon/cphalcon","slug":"loadfromconfig-requires-an-array-or-phalcon-config","errorCode":null,"errorMessage":"loadFromConfig requires an array or Phalcon\\Config\\ConfigInterface instance","messagePattern":"loadFromConfig requires an array or Phalcon\\\\Config\\\\ConfigInterface instance","errorType":"exception","errorClass":"Phalcon\\Mvc\\Router\\Exceptions\\InvalidConfigSource","httpStatus":null,"severity":"error","filePath":"phalcon/Mvc/Router.zep","lineNumber":1751,"sourceCode":"     *                  'pattern' => '/users',\n     *                  'paths'   => 'Users::index',\n     *              ],\n     *          ],\n     *      ]\n     *  );\n     *```\n     *\n     * @param array|ConfigInterface config\n     *\n     * @return static\n     */\n    public function loadFromConfig(var config) -> <static>\n    {\n        var routes, routeData, defaults, notFoundPaths, removeExtra, groups, groupData;\n\n        if typeof config === \"object\" {\n            if !(config instanceof ConfigInterface) {\n                throw new InvalidConfigSource();\n            }\n            let config = config->toArray();\n        }\n\n        if typeof config !== \"array\" {\n            throw new InvalidConfigSource();\n        }\n\n        if isset config[\"removeExtraSlashes\"] {\n            let removeExtra = config[\"removeExtraSlashes\"];\n            this->removeExtraSlashes((bool) removeExtra);\n        }\n\n        if isset config[\"defaults\"] {\n            let defaults = config[\"defaults\"];\n            if typeof defaults !== \"array\" {\n                throw new ConfigKeyMustBeArray(\"defaults\");\n            }","sourceCodeStart":1733,"sourceCodeEnd":1769,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Mvc/Router.zep#L1733-L1769","documentation":"Router::loadFromConfig() only accepts a plain array or a Phalcon\\Config\\ConfigInterface instance. This variant is thrown when you pass an object that is neither: the router will not guess how to read arbitrary objects (stdClass, SimpleXMLElement, another library's config object).","triggerScenarios":"$router->loadFromConfig(new \\stdClass()); passing a SimpleXML or nested generic object parsed from XML; passing a config object from a different package that mimics Config but does not implement Phalcon\\Config\\ConfigInterface.","commonSituations":"Loading routes from an XML file with simplexml_load_file() and passing the result directly; adapters migrating from Zend/Laminas or Symfony config objects; wrapping route config in a custom value object.","solutions":["Convert first: $router->loadFromConfig($config->toArray());","Or wrap the array: $router->loadFromConfig(new \\Phalcon\\Config\\Config($routeArray));","If parsing XML, cast to a plain array before passing (e.g. json_decode(json_encode($xml), true))"],"exampleFix":"// before\n$xml  = simplexml_load_file('app/config/routes.xml');\n$router->loadFromConfig($xml);\n\n// after\n$xml   = simplexml_load_file('app/config/routes.xml');\n$routes = json_decode(json_encode($xml), true);\n$router->loadFromConfig($routes);","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"use Phalcon\\Config\\ConfigInterface;\n\nfunction isLoadableConfig(mixed $config): bool\n{\n    return is_array($config) || $config instanceof ConfigInterface;\n}","tryCatchPattern":"try {\n    $router->loadFromConfig($config);\n} catch (\\Phalcon\\Mvc\\Router\\Exceptions\\InvalidConfigSource $e) {\n    throw new InvalidArgumentException(\n        'routes config must be array or Phalcon\\Config\\Config; got ' . get_debug_type($config)\n    );\n}","preventionTips":["Normalize before the call: if (is_object($config)) { $config = $config instanceof ConfigInterface ? $config->toArray() : (array) $config; }","Standardize on plain arrays for route config in your codebase to sidestep object-type ambiguity","For XML sources, convert to array immediately after parsing"],"tags":["phalcon","router","config","load-from-config","validation"],"backgroundTag":"config-validation-failed","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}