{"record":{"id":"be012f31ed597f0b","repo":"phalcon/cphalcon","slug":"invalid-data-type-for-merge","errorCode":null,"errorMessage":"Invalid data type for merge.","messagePattern":"Invalid data type for merge\\.","errorType":"exception","errorClass":"Phalcon\\Config\\Exceptions\\InvalidMergeData","httpStatus":null,"severity":"error","filePath":"phalcon/Config/Config.zep","lineNumber":92,"sourceCode":"     *\n     * $globalConfig->merge($appConfig);\n     *```\n     *\n     * @param array|ConfigInterface $toMerge\n     *\n     * @return ConfigInterface\n     * @throws Exception\n     */\n    public function merge(var toMerge) -> <ConfigInterface>\n    {\n        var result, source, target;\n\n        if typeof toMerge === \"array\" {\n            let target = toMerge;\n        } elseif typeof toMerge === \"object\" && toMerge instanceof ConfigInterface {\n            let target = toMerge->toArray();\n        } else {\n            throw new InvalidMergeData();\n        }\n\n        let source = this->toArray();\n\n        this->clear();\n\n        let result = this->internalMerge(source, target);\n\n        this->init(result);\n\n        return this;\n    }\n\n    /**\n     * Returns a value from current config using a dot separated path.\n     *\n     *```php\n     * echo $config->path(\"unknown.path\", \"default\", \".\");","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Config/Config.zep#L74-L110","documentation":"Config::merge() accepts only an array or an object implementing Phalcon\\Config\\ConfigInterface. Scalars are rejected outright, and so are plain objects — a stdClass with config-like keys still throws InvalidMergeData because the object branch is guarded by instanceof ConfigInterface.","triggerScenarios":"$config->merge(json_decode($json)) — stdClass because the assoc argument was omitted; $config->merge('production'); merging a SimpleXML or stdClass payload from an API.","commonSituations":"Decoding JSON without true as the second argument; merging data from sources that return objects (APIs, SimpleXML); merging env-derived values that are plain strings.","solutions":["Decode JSON with assoc: json_decode($json, true)","Wrap arrays in a Config instance: $config->merge(new Config($array))","Cast plain objects before merging: $config->merge((array) $object)"],"exampleFix":"// before\n$config->merge(json_decode($rawJson));\n\n// after\n$config->merge(json_decode($rawJson, true));","handlingStrategy":"type-guard","validationCode":"if (!is_array($toMerge) && !$toMerge instanceof \\Phalcon\\Config\\ConfigInterface) {\n    throw new InvalidArgumentException(sprintf(\n        'Config::merge() needs array or ConfigInterface, %s given',\n        gettype($toMerge)\n    ));\n}\n$config->merge($toMerge);","typeGuard":"/**\n * merge() accepts arrays and ConfigInterface objects only;\n * stdClass and scalars are rejected even when they look like config.\n */\nfunction isMergeableConfig($value): bool\n{\n    return is_array($value) || $value instanceof \\Phalcon\\Config\\ConfigInterface;\n}","tryCatchPattern":"try {\n    $config->merge($incoming);\n} catch (\\Phalcon\\Config\\Config\\Exception\\InvalidMergeData $e) {\n    // Coerce common object payloads and retry\n    if (is_object($incoming)) {\n        $config->merge((array) $incoming);\n    }\n}","preventionTips":["Always call json_decode($raw, true) before merging decoded data","Wrap raw arrays in new Config($array) when passing between layers","Cast stdClass with (array) or get_object_vars() before merge()"],"tags":["phalcon","config","merge","type-error","configuration"],"backgroundTag":"invalid-argument-type","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}