{"record":{"id":"7e1bbb8e5c2868d3","repo":"phalcon/cphalcon","slug":"the-directories-parameter-is-not-a-string-or-array","errorCode":null,"errorMessage":"The directories parameter is not a string or array for the '{name}' namespace","messagePattern":"The directories parameter is not a string or array for the '(.+?)' namespace","errorType":"exception","errorClass":"Phalcon\\Autoload\\Exceptions\\LoaderDirectoriesNotArray","httpStatus":null,"severity":"error","filePath":"phalcon/Autoload/Loader.zep","lineNumber":658,"sourceCode":"     * Checks if the directories is an array or a string and throws an exception\n     * if not. It converts the string to an array and then traverses the array\n     * to normalize the directories with the proper directory separator at the\n     * end\n     *\n     * @param mixed $directories\n     *\n     * @return autoload_strings\n     */\n    private function checkDirectories(\n        directories,\n        string dirSeparator,\n        string name = \"\"\n    ) -> array {\n        var directory;\n        array results;\n\n        if (!is_string(directories) && !is_array(directories)) {\n            throw new LoaderDirectoriesNotArray(name);\n        }\n\n        if (is_string(directories)) {\n            let directories = [directories];\n        }\n\n        let results = [];\n        for directory in directories {\n            let directory = rtrim(directory, dirSeparator) . dirSeparator;\n\n            let results[directory] = directory;\n        }\n\n        return results;\n    }\n\n    private function registerAutoload(bool prepend) -> bool\n    {","sourceCodeStart":640,"sourceCodeEnd":676,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Autoload/Loader.zep#L640-L676","documentation":"Loader::checkDirectories() normalizes the directories argument for registerNamespaces()/registerClasses()/registerDirs()-style registration (the 'name' in the message is the namespace/class key when applicable). Each directories value must be a string or an array of strings; anything else (null, int, object, bool) throws LoaderDirectoriesNotArray with the offending namespace name in the message.","triggerScenarios":"$loader->registerNamespaces(['App' => null]); $loader->registerNamespaces(['App' => 123]); passing an object or boolean as the directory spec for a namespace; registerDirs() fed a non-array/non-string value.","commonSituations":"Env-driven paths that resolve to null when an env var is missing; config merges that null out namespace paths; YAML parsing an unquoted numeric path as int; refactoring that leaves a namespace key without its directories.","solutions":["Give the namespace a real path string or array of strings: $loader->registerNamespaces(['App' => app_path()])","Sanitize config-derived values: array_filter($paths) to drop nulls before registering","Guard env-derived roots: $paths['App'] = $envRoot ?? __DIR__ . '/src'"],"exampleFix":"// before\n$loader->registerNamespaces(['App' => getenv('APP_PATH')]); // false/null when unset\n\n// after\n$loader->registerNamespaces(['App' => getenv('APP_PATH') ?: __DIR__ . '/../src']);","handlingStrategy":"type-guard","validationCode":"foreach ($namespaces as $ns => $dirs) {\n    if (!is_string($dirs) && !is_array($dirs)) {\n        unset($namespaces[$ns]); // or throw with the namespace name\n    }\n}\n$loader->registerNamespaces($namespaces);","typeGuard":"function isValidDirectorySpec($dirs): bool\n{\n    return is_string($dirs) || is_array($dirs);\n}","tryCatchPattern":null,"preventionTips":["array_filter namespace/path maps before registering to drop null/false values","Default env-derived roots with ?? or ?: so they are never null/false","Quote path values in YAML/ENV configs to avoid numeric coercion"],"tags":["autoload","loader","namespaces","configuration"],"backgroundTag":"invalid-autoload-config","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}