{"record":{"id":"99b58e14df1e9cbc","repo":"phalcon/cphalcon","slug":"config-must-be-array-or-phalcon-config-config-obje","errorCode":null,"errorMessage":"Config must be array or Phalcon\\Config\\Config object","messagePattern":"Config must be array or Phalcon\\\\Config\\\\Config object","errorType":"exception","errorClass":"Phalcon\\Config\\Exceptions\\ConfigNotArrayOrObject","httpStatus":null,"severity":"error","filePath":"phalcon/Config/ConfigFactory.zep","lineNumber":207,"sourceCode":"            let oldConfig = config,\n                extension = pathinfo(config, PATHINFO_EXTENSION);\n\n            if true  == empty(extension) {\n                throw new MissingFileExtension();\n            }\n\n            let config = [\n                \"adapter\"  : extension,\n                \"filePath\" : oldConfig\n            ];\n        }\n\n        if typeof config === \"object\" && config instanceof ConfigInterface {\n            let config = config->toArray();\n        }\n\n        if typeof config !== \"array\" {\n            throw new ConfigNotArrayOrObject();\n        }\n\n        this->checkConfigArray(config);\n\n        return config;\n    }\n\n    /**\n     * @param array $config\n     *\n     * @throws Exception\n     */\n    private function checkConfigArray(array config) -> void\n    {\n        if true !== isset(config[\"filePath\"]) {\n            throw new MissingConfigOption(\"filePath\");\n        }\n","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Config/ConfigFactory.zep#L189-L225","documentation":"ConfigFactory::load()/parseConfig normalizes its input: a file-path string becomes an adapter+filePath array, and a ConfigInterface object becomes an array via toArray(). Whatever is still not an array afterwards throws ConfigNotArrayOrObject — so integers, floats, booleans, null, and plain (non-Config) objects are rejected.","triggerScenarios":"$factory->load(0), load(true), load(new stdClass()), or load($json) where a failed json_decode returned null.","commonSituations":"Config paths pulled from getenv() that default to false; a config variable coming back null from a cache miss; passing SimpleXMLElement or stdClass from external sources.","solutions":["Pass one of the three supported forms: a file-path string, an array with filePath+adapter, or a Config instance","Check the type before calling load() when the value comes from env/cache/remote sources","Use json_decode($raw, true) so decoded data is an array, not stdClass/null"],"exampleFix":"// before\n$source = $cache->get('app-config'); // null on miss\n$config = $factory->load($source);\n\n// after\n$source = $cache->get('app-config') ?: '/etc/myapp/config.ini';\nif (!is_string($source) && !is_array($source)) {\n    throw new InvalidArgumentException('Unsupported config source type');\n}\n$config = $factory->load($source);","handlingStrategy":"type-guard","validationCode":"if (!is_string($source) && !is_array($source) && !$source instanceof \\Phalcon\\Config\\ConfigInterface) {\n    throw new InvalidArgumentException(sprintf(\n        'ConfigFactory expects string path, array config, or ConfigInterface; %s given',\n        gettype($source)\n    ));\n}\n$config = $factory->load($source);","typeGuard":"/**\n * The factory accepts a file-path string (with extension),\n * an array with filePath/adapter, or a ConfigInterface instance.\n */\nfunction isConfigFactoryInput($value): bool\n{\n    return is_string($value)\n        || is_array($value)\n        || $value instanceof \\Phalcon\\Config\\ConfigInterface;\n}","tryCatchPattern":"try {\n    $config = $factory->load($source);\n} catch (\\Phalcon\\Config\\ConfigFactory\\Exception\\ConfigNotArrayOrObject $e) {\n    // Source degraded to null/bool/int (cache miss, failed decode); reload from the default path\n    $config = $factory->load('/etc/myapp/config.ini');\n}","preventionTips":["Default env-derived config variables to a real path string, not false/null","json_decode with assoc=true so decoded sources stay arrays","Assert the type once at the boundary (CLI/env/cache) instead of trusting it at load()"],"tags":["phalcon","config","factory","type-error","configuration"],"backgroundTag":"config-validation-failed","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}