{"record":{"id":"660aba584417cf64","repo":"cakephp/cakephp","slug":"the-s-has-already-been-loaded","errorCode":null,"errorMessage":"The `%s` has already been loaded.","messagePattern":"The `(.+?)` has already been loaded\\.","errorType":"exception","errorClass":"Cake\\Core\\Exception\\CakeException","httpStatus":null,"severity":"error","filePath":"src/Core/ObjectRegistry.php","lineNumber":139,"sourceCode":"     * bad and an exception will be raised.\n     *\n     * An exception is raised, as replacing the object will not update any\n     * references other objects may have. Additionally, simply updating the runtime\n     * configuration is not a good option as we may be missing important constructor\n     * logic dependent on the configuration.\n     *\n     * @param string $name The name of the alias in the registry.\n     * @param array<string, mixed> $config The config data for the new instance.\n     * @return void\n     * @throws \\Cake\\Core\\Exception\\CakeException When a duplicate is found.\n     */\n    protected function _checkDuplicate(string $name, array $config): void\n    {\n        $existing = $this->_loaded[$name];\n        $msg = sprintf('The `%s` alias has already been loaded.', $name);\n        $hasConfig = method_exists($existing, 'getConfig');\n        if (!$hasConfig) {\n            throw new CakeException($msg);\n        }\n        if (!$config) {\n            return;\n        }\n        $existingConfig = $existing->getConfig();\n        unset($config['enabled'], $existingConfig['enabled']);\n\n        $failure = null;\n        foreach ($config as $key => $value) {\n            if (!array_key_exists($key, $existingConfig)) {\n                $failure = \" The `{$key}` was not defined in the previous configuration data.\";\n                break;\n            }\n            if (isset($existingConfig[$key]) && $existingConfig[$key] !== $value) {\n                $failure = sprintf(\n                    ' The `%s` key has a value of `%s` but previously had a value of `%s`',\n                    $key,\n                    json_encode($value, JSON_THROW_ON_ERROR),","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/cakephp/cakephp/blob/1128eba9b09f1946df684811350e26f2cef68fac/src/Core/ObjectRegistry.php#L121-L157","documentation":"ObjectRegistry::_checkDuplicate() detects loading the same alias twice. If the previously loaded object does not implement getConfig(), the registry cannot compare configurations, so it throws immediately — reloading an alias with a different class/config cannot be reconciled safely.","triggerScenarios":"Calling $registry->load('HelperName') twice where the first loaded object lacks a getConfig() method (legacy/plain object); loading a helper/component alias that collides with an already-loaded non-configurable object.","commonSituations":"Plugins that map an alias to a custom class while core already loaded the same alias; duplicate ->load() calls in both a controller's $helpers property and its initialize(); old third-party helpers without the getConfig() API.","solutions":["Remove the duplicate load() call, or the duplicate entry in the $helpers/$components property array","Unload first with $registry->unload($name) before re-loading with different config","Check for alias collisions between plugins and core (use a unique alias with 'className' => RealClass)","Upgrade legacy objects to implement ConfigTrait/getConfig() so config comparison works"],"exampleFix":"// before\nclass AppController {\n    public $helpers = ['Form'];\n    public function initialize() { $this->loadHelper('Form'); } // duplicate\n}\n\n// after\nclass AppController {\n    public $helpers = ['Form']; // loaded once, or use unload() before reload\n}","handlingStrategy":"try-catch","validationCode":"if ($registry->has($name)) {\n    $registry->unload($name);\n}\n$registry->load($name, $config);","typeGuard":null,"tryCatchPattern":"try {\n    $registry->load($name, $config);\n} catch (CakeException $e) {\n    error_log('Duplicate load: ' . $e->getMessage());\n}","preventionTips":["Load each alias in exactly one place (property list or initialize, not both)","Use unique aliases with 'className' for plugin class swaps","Unload before reloading with different config","Ensure custom objects implement getConfig() so duplicates can be reconciled"],"tags":["php","cakephp","registry","duplicate"],"backgroundTag":"conflicting-config-options","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"}