{"record":{"id":"5a6d740b28a688dc","repo":"cakephp/cakephp","slug":"invalid-merge-strategy-valid-options-are-deep-shallow","errorCode":null,"errorMessage":"Invalid merge strategy. Valid options are: `deep`, `shallow`.","messagePattern":"Invalid merge strategy\\. Valid options are: `deep`, `shallow`\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/View/ViewBuilder.php","lineNumber":540,"sourceCode":"    }\n\n    /**\n     * Set the config merge strategy for view options.\n     *\n     * Can be:\n     *  - 'deep': Recursive merge (default for BC, merges nested arrays)\n     *  - 'shallow': Simple array merge (replaces array values)\n     *\n     * This controls how options set via ViewBuilder are merged with\n     * the View class's default configuration.\n     *\n     * @param self::MERGE_DEEP|self::MERGE_SHALLOW $strategy The merge strategy.\n     * @return $this\n     */\n    public function setConfigMergeStrategy(string $strategy)\n    {\n        if (!in_array($strategy, [self::MERGE_DEEP, self::MERGE_SHALLOW], true)) {\n            throw new InvalidArgumentException('Invalid merge strategy. Valid options are: `deep`, `shallow`.');\n        }\n\n        $this->_configMergeStrategy = $strategy;\n\n        return $this;\n    }\n\n    /**\n     * Get the config merge strategy.\n     *\n     * @return self::MERGE_DEEP|self::MERGE_SHALLOW\n     */\n    public function getConfigMergeStrategy(): string\n    {\n        return $this->_configMergeStrategy;\n    }\n\n    /**","sourceCodeStart":522,"sourceCodeEnd":558,"githubUrl":"https://github.com/cakephp/cakephp/blob/1128eba9b09f1946df684811350e26f2cef68fac/src/View/ViewBuilder.php#L522-L558","documentation":"ViewBuilder::setConfigMergeStrategy() accepts only the class constants MERGE_DEEP ('deep') or MERGE_SHALLOW ('shallow'). Any other string is rejected with InvalidArgumentException because the strategy controls how ViewBuilder configs are merged and an unknown value would silently change merging semantics.","triggerScenarios":"Calling $builder->setConfigMergeStrategy('Deep'), 'merge', 'default', or any string other than exactly 'deep' or 'shallow'.","commonSituations":"Passing a user/config-supplied string; typos or wrong casing; confusing this with other frameworks' merge option names.","solutions":["Use ViewBuilder::MERGE_DEEP or ViewBuilder::MERGE_SHALLOW constants instead of raw strings","Correct the string to exactly 'deep' or 'shallow' (lowercase)","Validate/whitelist the value before passing it if it comes from configuration"],"exampleFix":"// before\n$builder->setConfigMergeStrategy('recursive');\n// after\n$builder->setConfigMergeStrategy(ViewBuilder::MERGE_DEEP);","handlingStrategy":"validation","validationCode":"$allowed = [ViewBuilder::MERGE_DEEP, ViewBuilder::MERGE_SHALLOW];\nif (!in_array($strategy, $allowed, true)) { throw new \\InvalidArgumentException('bad strategy'); }\n$builder->setConfigMergeStrategy($strategy);","typeGuard":"$strategy = in_array($strategy, ['deep','shallow'], true) ? $strategy : ViewBuilder::MERGE_DEEP;","tryCatchPattern":"try { $builder->setConfigMergeStrategy($strategy); } catch (\\InvalidArgumentException $e) { $builder->setConfigMergeStrategy(ViewBuilder::MERGE_DEEP); }","preventionTips":["Always pass the MERGE_* class constants","Whitelist values coming from config files","Lowercase-normalize external input before use"],"tags":["cakephp","viewbuilder","config","invalid-argument"],"backgroundTag":"invalid-enum-value","analyzedSha":"1128eba9b09f1946df684811350e26f2cef68fac","analyzedAt":"2026-09-12T12:07:00.388Z","contentChangedAt":"2026-09-12T12:07:00.388Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}