phalcon/cphalcon · error · Phalcon\Mvc\Router\Exceptions\InvalidConfigSource

loadFromConfig requires an array or Phalcon\Config\ConfigInt

Error message

loadFromConfig requires an array or Phalcon\Config\ConfigInterface instance

What it means

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).

Source

Thrown at phalcon/Mvc/Router.zep:1751

     *                  'pattern' => '/users',
     *                  'paths'   => 'Users::index',
     *              ],
     *          ],
     *      ]
     *  );
     *```
     *
     * @param array|ConfigInterface config
     *
     * @return static
     */
    public function loadFromConfig(var config) -> <static>
    {
        var routes, routeData, defaults, notFoundPaths, removeExtra, groups, groupData;

        if typeof config === "object" {
            if !(config instanceof ConfigInterface) {
                throw new InvalidConfigSource();
            }
            let config = config->toArray();
        }

        if typeof config !== "array" {
            throw new InvalidConfigSource();
        }

        if isset config["removeExtraSlashes"] {
            let removeExtra = config["removeExtraSlashes"];
            this->removeExtraSlashes((bool) removeExtra);
        }

        if isset config["defaults"] {
            let defaults = config["defaults"];
            if typeof defaults !== "array" {
                throw new ConfigKeyMustBeArray("defaults");
            }

View on GitHub (pinned to b7419de9cd)

Solutions

  1. Convert first: $router->loadFromConfig($config->toArray());
  2. Or wrap the array: $router->loadFromConfig(new \Phalcon\Config\Config($routeArray));
  3. If parsing XML, cast to a plain array before passing (e.g. json_decode(json_encode($xml), true))

Example fix

// before
$xml  = simplexml_load_file('app/config/routes.xml');
$router->loadFromConfig($xml);

// after
$xml   = simplexml_load_file('app/config/routes.xml');
$routes = json_decode(json_encode($xml), true);
$router->loadFromConfig($routes);
Defensive patterns

Strategy: type-guard

Type guard

use Phalcon\Config\ConfigInterface;

function isLoadableConfig(mixed $config): bool
{
    return is_array($config) || $config instanceof ConfigInterface;
}

Try / catch

try {
    $router->loadFromConfig($config);
} catch (\Phalcon\Mvc\Router\Exceptions\InvalidConfigSource $e) {
    throw new InvalidArgumentException(
        'routes config must be array or Phalcon\Config\Config; got ' . get_debug_type($config)
    );
}

Prevention

When it happens

Trigger: $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.

Common situations: 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.

Understand the failure class

Background: Config validation failed: what "invalid value for {key}" and settings-rejection errors mean across 19 open-source libraries — this error's family across 19 libraries.

Related errors


AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21). Data as JSON: /api/errors/d5daaa324055458f. Report an issue: GitHub.