{"record":{"id":"7e2e45f6919961fc","repo":"phalcon/cphalcon","slug":"arguments-must-be-an-array-or-string-type-given","errorCode":null,"errorMessage":"Arguments must be an array or string, {type} given","messagePattern":"Arguments must be an array or string, (.+?) given","errorType":"exception","errorClass":"Phalcon\\Cli\\Router\\Exceptions\\RouterArgumentsInvalidType","httpStatus":null,"severity":"error","filePath":"phalcon/Cli/Router.zep","lineNumber":239,"sourceCode":"     *\n     * @phpstan-param mixed $arguments\n     */\n    public function handle(arguments = null)\n    {\n        var moduleName, taskName, actionName, params, route, parts, pattern,\n            routeFound, matches, paths, beforeMatch, converters, converter,\n            part, position, matchPosition, strParams;\n\n        let routeFound = false,\n            parts = [],\n            params = [],\n            matches = null,\n            this->wasMatched = false,\n            this->matchedRoute = null;\n\n        if typeof arguments !== \"array\" {\n            if unlikely (typeof arguments != \"string\" && arguments !== null) {\n                throw new RouterArgumentsInvalidType(gettype(arguments));\n            }\n\n            for route in reverse this->routes {\n                /**\n                 * If the route has parentheses use preg_match\n                 */\n                let pattern = route->getCompiledPattern();\n\n                if memstr(pattern, \"^\") {\n                    let routeFound = preg_match(pattern, arguments, matches);\n                } else {\n                    let routeFound = pattern == arguments;\n                }\n\n                /**\n                 * Check for beforeMatch conditions\n                 */\n                if routeFound {","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Cli/Router.zep#L221-L257","documentation":"Cli\\Router::handle() accepts arguments only as an array (typically $_SERVER['argv']), a string, or null. Any other type — int, float, bool, object — throws RouterArgumentsInvalidType, with the actual gettype() of the value embedded in the message.","triggerScenarios":"$router->handle(3) passing a count, handle(true), or handle(new ArrayObject($argv)) — objects with __toString are also rejected because the check is on typeof, not on convertibility.","commonSituations":"Passing a normalized/computed value that silently became a non-string scalar (e.g. an option count or exit code instead of the arguments); passing an argv wrapper object; passing $_GET into a CLI router by copy-paste.","solutions":["Cast scalars before calling: $router->handle((string) $arguments)","Pass the raw argv array: $router->handle($_SERVER['argv'] ?? null)","Pass null to reset the router state intentionally"],"exampleFix":"// before\n$router->handle($argc);\n\n// after\n$router->handle($_SERVER['argv'] ?? null);","handlingStrategy":"type-guard","validationCode":"$arguments = $_SERVER['argv'] ?? null;\nif ($arguments !== null && !is_array($arguments) && !is_string($arguments)) {\n    throw new InvalidArgumentException(sprintf(\n        'Router arguments must be array|string|null, %s given',\n        gettype($arguments)\n    ));\n}\n$router->handle($arguments);","typeGuard":"/**\n * Cli\\Router::handle() accepts only array, string, or null.\n */\nfunction isRouterArguments($value): bool\n{\n    return $value === null || is_string($value) || is_array($value);\n}","tryCatchPattern":"try {\n    $router->handle($arguments);\n} catch (\\Phalcon\\Cli\\Router\\Exception\\RouterArgumentsInvalidType $e) {\n    // Message names the actual type received; coerce and retry once with a string\n    $router->handle((string) $arguments);\n}","preventionTips":["Pass $_SERVER['argv'] (or null) instead of derived scalar values","Cast any computed string-ish scalar with (string) before handle()","Remember objects with __toString do not pass — convert them explicitly"],"tags":["phalcon","cli","router","arguments","type-error"],"backgroundTag":"invalid-argument-type","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}