{"record":{"id":"ef5fe6911f1b2c52","repo":"cakephp/cakephp","slug":"option-s-is-not-of-type-array-use-getoption-instead","errorCode":null,"errorMessage":"Option `%s` is not of type `array`, use `getOption()` instead.","messagePattern":"Option `(.+?)` is not of type `array`, use `getOption\\(\\)` instead\\.","errorType":"exception","errorClass":"Cake\\Console\\Exception\\ConsoleException","httpStatus":null,"severity":"error","filePath":"src/Console/Arguments.php","lineNumber":270,"sourceCode":"    {\n        deprecationWarning(\n            '5.2.0',\n            'getMultipleOption() is deprecated. Use `getArrayOption()` instead.',\n        );\n\n        return $this->getArrayOption($name);\n    }\n\n    /**\n     * Gets a multiple (array) option's value or null if not set.\n     *\n     * @return array<string>|null\n     */\n    public function getArrayOption(string $name): ?array\n    {\n        $value = $this->options[$name] ?? null;\n        if ($value !== null && !is_array($value)) {\n            throw new ConsoleException(sprintf(\n                'Option `%s` is not of type `array`, use `getOption()` instead.',\n                $name,\n            ));\n        }\n\n        return $value;\n    }\n\n    /**\n     * Check if an option is defined and not null.\n     *\n     * @param string $name The name of the option to check.\n     * @return bool\n     */\n    public function hasOption(string $name): bool\n    {\n        return isset($this->options[$name]);\n    }","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/cakephp/cakephp/blob/1128eba9b09f1946df684811350e26f2cef68fac/src/Console/Arguments.php#L252-L288","documentation":"Arguments::getArrayOption() returns a repeatable option as ?array. If the option's stored value is a scalar string or bool rather than an array, it throws ConsoleException and tells you to use getOption().","triggerScenarios":"Calling getArrayOption('opt') when $this->options['opt'] is a string (single occurrence as value option) or bool (bare flag), i.e. the option was not given multiple values.","commonSituations":"Using the array getter for an option typically passed once (--env=prod); tests or commands where the option appears only once; confusion between flag/value/repeatable option kinds.","solutions":["Use getOption($name) for single-occurrence options","Ensure callers actually repeat the option if array semantics are intended","Normalize: $opt = is_array($raw) ? $raw : ($raw === null ? null : [$raw]);"],"exampleFix":"// before\n$env = $args->getArrayOption('env');\n// after\n$env = $args->getOption('env');","handlingStrategy":"type-guard","validationCode":"$raw = $args->getOption('env');\nif (is_array($raw)) { $env = $args->getArrayOption('env'); } else { $env = $raw === null ? null : [$raw]; }","typeGuard":"function expectArrayOption(\\Cake\\Console\\Arguments $a, string $name): ?array {\n    $v = $a->getArrayOption($name);\n    if ($v !== null && !is_array($v)) { throw new \\LogicException(\"'$name' is not repeatable; use getOption()\"); }\n    return $v;\n}","tryCatchPattern":"try {\n    $values = $args->getArrayOption('env');\n} catch (\\Cake\\Console\\Exception\\ConsoleException $e) {\n    $one = $args->getOption('env');\n    $values = $one === null ? null : [$one];\n}","preventionTips":["Reserve getArrayOption for options users are expected to repeat","Normalize single/multiple occurrences in one helper function","Cover both `--opt x` and `--opt x --opt y` invocations in tests"],"tags":["cli","php","options","type-mismatch"],"backgroundTag":"invalid-argument-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"}