{"record":{"id":"3370e09a628d66b9","repo":"yiisoft/yii2","slug":"missing-required-parameter-name-when-calling","errorCode":null,"errorMessage":"Missing required parameter \"$name\" when calling \"$funcName\".","messagePattern":"Missing required parameter \"\\$name\" when calling \"\\$funcName\"\\.","errorType":"exception","errorClass":"InvalidConfigException","httpStatus":null,"severity":"error","filePath":"framework/di/Container.php","lineNumber":733,"sourceCode":"                        $args[] = $this->get($className);\n                    } catch (NotInstantiableException $e) {\n                        if ($param->isDefaultValueAvailable()) {\n                            $args[] = $param->getDefaultValue();\n                        } else {\n                            throw $e;\n                        }\n                    }\n                }\n            } elseif ($associative && isset($params[$name])) {\n                $args[] = $params[$name];\n                unset($params[$name]);\n            } elseif (!$associative && count($params)) {\n                $args[] = array_shift($params);\n            } elseif ($param->isDefaultValueAvailable()) {\n                $args[] = $param->getDefaultValue();\n            } elseif (!$param->isOptional()) {\n                $funcName = $reflection->getName();\n                throw new InvalidConfigException(\"Missing required parameter \\\"$name\\\" when calling \\\"$funcName\\\".\");\n            }\n        }\n\n        foreach ($params as $value) {\n            $args[] = $value;\n        }\n\n        return $args;\n    }\n\n    /**\n     * Registers class definitions within this container.\n     *\n     * @param array $definitions array of definitions. There are two allowed formats of array.\n     * The first format:\n     *  - key: class name, interface name or alias name. The key will be passed to the [[set()]] method\n     *    as a first argument `$class`.\n     *  - value: the definition associated with `$class`. Possible values are described in","sourceCodeStart":715,"sourceCodeEnd":751,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/di/Container.php#L715-L751","documentation":"yii\\di\\Container throws this InvalidConfigException from resolveCallableDependencies() while building arguments for Container::invoke() (or any callable resolved through the container). A non-class-typed parameter that is not supplied by name (associative call) or positionally, has no default value, and is not optional, cannot be resolved - class-typed parameters are autowired, but scalars never are - so the container reports exactly which parameter of which function is missing.","triggerScenarios":"Yii::$container->invoke([$service, 'send'], ['to' => 'a@b.c']) where send(string $to, string $message) is called without 'message'; invoking a closure via the container with a required scalar argument left out; passing an associative array whose keys don't match the parameter names.","commonSituations":"Refactoring a method signature to add a required parameter and forgetting to update every invoke() call site; typos in parameter-name keys of the $params array ('userName' vs 'name'); switching a positional call to named arguments with wrong keys.","solutions":["Supply the missing argument: pass it by name in the params array, e.g. invoke($callable, ['to' => ..., 'message' => ...]).","Give the parameter a default value or make it optional in the callable's signature.","If the parameter is class-typed, type-hint it so the container autowires it instead of demanding a scalar.","Check spelling/case of keys in an associative params array against the real parameter names."],"exampleFix":"// before\nYii::$container->invoke([$service, 'send'], ['to' => 'a@b.c']);\n// send(string $to, string $message) -> Missing required parameter \"message\"\n\n// after\nYii::$container->invoke([$service, 'send'], ['to' => 'a@b.c', 'message' => 'Hello']);\n\n// or make it optional in the callee\npublic function send(string $to, string $message = ''): void","handlingStrategy":"validation","validationCode":"use yii\\di\\Container;\n\n$reflection = new \\ReflectionMethod($service, 'send');\n$params = ['to' => 'a@b.c'];\nforeach ($reflection->getParameters() as $p) {\n    if (!$p->isOptional() && !isset($params[$p->getName()]) && $p->getType() !== null && $p->getType()->isBuiltin()) {\n        $params[$p->getName()] = /* supply a value */ '';\n    }\n}\nYii::$container->invoke([$service, 'send'], $params);","typeGuard":"/** True when every non-optional scalar param of the callable is supplied. */\nfunction paramsComplete(callable $fn, array $params): bool\n{\n    $ref = is_array($fn) ? new \\ReflectionMethod($fn[0], $fn[1]) : new \\ReflectionFunction(\\Closure::fromCallable($fn));\n    foreach ($ref->getParameters() as $p) {\n        $builtin = $p->getType() === null || $p->getType()->isBuiltin();\n        if ($builtin && !$p->isOptional() && !array_key_exists($p->getName(), $params)) {\n            return false;\n        }\n    }\n    return true;\n}","tryCatchPattern":"use yii\\base\\InvalidConfigException;\n\ntry {\n    Yii::$container->invoke([$service, 'send'], $params);\n} catch (InvalidConfigException $e) {\n    if (strpos($e->getMessage(), 'Missing required parameter') === 0) {\n        // log the callable + params, surface a 422 to the caller\n    } else {\n        throw $e;\n    }\n}","preventionTips":["Give invoke()-target callables sensible defaults or make added parameters optional.","Use named keys in the params array that exactly match parameter names (they are case-sensitive).","After changing a method signature, grep for invoke( call sites passing positional/named params.","Type-hint injectable dependencies so the container autowires them instead of demanding scalars."],"tags":["yii2","dependency-injection","container","invoke","invalid-config"],"backgroundTag":"missing-required-parameter","analyzedSha":"66f00d18a29b520f85e8e8f1e32d1e7e7b556cac","analyzedAt":"2026-08-17T05:17:23.470Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}