{"record":{"id":"59334b1b78461ce0","repo":"phalcon/cphalcon","slug":"service-is-required-in-parameter-on-position","errorCode":null,"errorMessage":"Service '{}' is required in parameter on position {}","messagePattern":"Service '(.+?)' is required in parameter on position (.+?)","errorType":"exception","errorClass":"MissingParameterKey","httpStatus":null,"severity":"error","filePath":"phalcon/Di/Service/Builder.zep","lineNumber":219,"sourceCode":"    private function buildParameter(<DiInterface> container, int position,  array argument)\n    {\n        var type, name, value, instanceArguments;\n\n        /**\n         * All the arguments must have a type\n         */\n        if unlikely !fetch type, argument[\"type\"] {\n            throw new ArgumentTypeRequired(position);\n        }\n\n        switch type {\n            /**\n             * If the argument type is 'service', we obtain the service from the\n             * DI\n             */\n            case \"service\":\n                if unlikely !fetch name, argument[\"name\"] {\n                    throw new MissingParameterKey(\"name\", position);\n                }\n\n                return container->get(name);\n\n            /**\n             * If the argument type is 'parameter', we assign the value as it is\n             */\n            case \"parameter\":\n                if unlikely !fetch value, argument[\"value\"] {\n                    throw new MissingParameterKey(\"value\", position);\n                }\n\n                return value;\n\n            /**\n             * If the argument type is 'instance', we assign the value as it is\n             */\n            case \"instance\":","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Di/Service/Builder.zep#L201-L237","documentation":"Thrown by Phalcon\\Di\\Service\\Builder::buildParameter() when an argument is declared with 'type' => 'service' but has no 'name' key. The 'service' type tells the builder to resolve another service from the container; the 'name' key is the service id it must fetch via container->get(name). Without it there is nothing to look up.","triggerScenarios":"A definition like ['type' => 'service'] (or with the key misspelled as 'service', 'serviceName', 'id') inside 'arguments' or 'calls' parameters, thrown when the parent service is resolved with $di->get()/injection. Message interpolates the missing key name: \"Service 'name' is required in parameter on position N\".","commonSituations":"Misspelling 'name' (e.g. 'serviceName'), renaming the target service and removing the entry, or assuming 'service' type takes the id under a different key. Frequently appears when wiring shared services like 'db' or 'config' into repositories via array definitions.","solutions":["Add the 'name' key naming an already-registered service: ['type' => 'service', 'name' => 'db'].","Verify the named service is actually registered ($di->has('db')) before relying on it.","Prefer a closure definition for complex wiring: $di->set('repo', fn() => new Repository($di->get('db'))) - no array schema to satisfy."],"exampleFix":"// before\n$di->set('userRepo', [\n    'className' => \\App\\UserRepository::class,\n    'arguments' => [\n        ['type' => 'service'],              // missing name\n    ],\n]);\n\n// after\n$di->set('userRepo', [\n    'className' => \\App\\UserRepository::class,\n    'arguments' => [\n        ['type' => 'service', 'name' => 'db'],\n    ],\n]);","handlingStrategy":"validation","validationCode":"function assertValidServiceArgument(array $arg, int $position): void\n{\n    if (($arg['type'] ?? null) === 'service' && !isset($arg['name'])) {\n        throw new InvalidArgumentException(\"Argument {$position}: type 'service' requires 'name'\");\n    }\n}\n// run over every 'arguments' entry before $di->set(...) with an array definition","typeGuard":"function resolvesKnownService(\\Phalcon\\Di\\DiInterface $di, array $arg): bool\n{\n    return ($arg['type'] ?? null) === 'service'\n        && isset($arg['name'])\n        && $di->has($arg['name']);\n}","tryCatchPattern":"try {\n    $obj = $di->get('reportService');\n} catch (\\Phalcon\\Di\\Exceptions\\MissingParameterKey $e) {\n    // e.getMessage() names the missing key ('name') and the position\n    $logger->error('Bad DI definition: ' . $e->getMessage());\n    throw new RuntimeException('Container misconfigured', 0, $e);\n}","preventionTips":["When registering 'service'-type arguments, assert $di->has($arg['name']) immediately - it catches both missing 'name' and unregistered targets at boot.","Unit-test one resolve of each config-defined service in CI."],"tags":["phalcon","dependency-injection","di","configuration","service-container"],"backgroundTag":"di-definition-invalid","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}