phalcon/cphalcon · error · MissingParameterKey
Service '{}' is required in parameter on position {}
Error message
Service '{}' is required in parameter on position {} What it means
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.
Source
Thrown at phalcon/Di/Service/Builder.zep:219
private function buildParameter(<DiInterface> container, int position, array argument)
{
var type, name, value, instanceArguments;
/**
* All the arguments must have a type
*/
if unlikely !fetch type, argument["type"] {
throw new ArgumentTypeRequired(position);
}
switch type {
/**
* If the argument type is 'service', we obtain the service from the
* DI
*/
case "service":
if unlikely !fetch name, argument["name"] {
throw new MissingParameterKey("name", position);
}
return container->get(name);
/**
* If the argument type is 'parameter', we assign the value as it is
*/
case "parameter":
if unlikely !fetch value, argument["value"] {
throw new MissingParameterKey("value", position);
}
return value;
/**
* If the argument type is 'instance', we assign the value as it is
*/
case "instance":View on GitHub (pinned to b7419de9cd)
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.
Example fix
// before
$di->set('userRepo', [
'className' => \App\UserRepository::class,
'arguments' => [
['type' => 'service'], // missing name
],
]);
// after
$di->set('userRepo', [
'className' => \App\UserRepository::class,
'arguments' => [
['type' => 'service', 'name' => 'db'],
],
]); Defensive patterns
Strategy: validation
Validate before calling
function assertValidServiceArgument(array $arg, int $position): void
{
if (($arg['type'] ?? null) === 'service' && !isset($arg['name'])) {
throw new InvalidArgumentException("Argument {$position}: type 'service' requires 'name'");
}
}
// run over every 'arguments' entry before $di->set(...) with an array definition Type guard
function resolvesKnownService(\Phalcon\Di\DiInterface $di, array $arg): bool
{
return ($arg['type'] ?? null) === 'service'
&& isset($arg['name'])
&& $di->has($arg['name']);
} Try / catch
try {
$obj = $di->get('reportService');
} catch (\Phalcon\Di\Exceptions\MissingParameterKey $e) {
// e.getMessage() names the missing key ('name') and the position
$logger->error('Bad DI definition: ' . $e->getMessage());
throw new RuntimeException('Container misconfigured', 0, $e);
} Prevention
- 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.
When it happens
Trigger: 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".
Common situations: 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.
Related errors
- Argument at position {} must have a type
- Service 'value' is required in parameter on position {}
- Service 'className' is required in parameter on position {}
- Unknown service type in parameter on position {}
- A dependency injection container is required to access the '
AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21).
Data as JSON: /api/errors/59334b1b78461ce0.
Report an issue: GitHub.