phalcon/cphalcon · error · MissingParameterKey
Service 'value' is required in parameter on position {}
Error message
Service 'value' is required in parameter on position {} What it means
Thrown by Phalcon\Di\Service\Builder::buildParameter() when an argument is declared with 'type' => 'parameter' but has no 'value' key. The 'parameter' type injects a literal value as-is; the 'value' key carries that literal. Without it the builder has nothing to pass to the constructor.
Source
Thrown at phalcon/Di/Service/Builder.zep:229
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":
if unlikely !fetch name, argument["className"] {
throw new MissingParameterKey("className", position);
}
if fetch instanceArguments, argument["arguments"] {
/**
* Build the instance with arguments
*/
return container->get(name, instanceArguments);
}View on GitHub (pinned to b7419de9cd)
Solutions
- Add the literal: ['type' => 'parameter', 'value' => 42].
- Check the position reported in the message (0-based) against your 'arguments' array to find the entry missing 'value'.
- If values come from config, assert the config key exists before building the definition.
Example fix
// before
$di->set('cache', [
'className' => \App\Cache::class,
'arguments' => [
['type' => 'parameter'], // missing value
],
]);
// after
$di->set('cache', [
'className' => \App\Cache::class,
'arguments' => [
['type' => 'parameter', 'value' => 3600],
],
]); Defensive patterns
Strategy: validation
Validate before calling
function assertParameterHasValue(array $arg, int $position): void
{
if (($arg['type'] ?? null) === 'parameter' && !array_key_exists('value', $arg)) {
throw new InvalidArgumentException("Argument {$position}: type 'parameter' requires 'value'");
}
} Type guard
function isParameterArgumentWithValue(mixed $arg): bool
{
return is_array($arg)
&& ($arg['type'] ?? null) === 'parameter'
&& array_key_exists('value', $arg); // value may legitimately be 0/false/null
} Try / catch
try {
$di->get('mailer');
} catch (\Phalcon\Di\Exceptions\MissingParameterKey $e) {
if (str_contains($e->getMessage(), "'value'")) {
// literal argument missing its value - definition bug, fix the config
}
throw $e;
} Prevention
- Use array_key_exists rather than isset when auditing definitions - a legitimate value of null or 0 must not be flagged.
- When definitions come from YAML/JSON, run the validator right after loading, before registration.
When it happens
Trigger: An argument entry like ['type' => 'parameter'] (or 'value' misspelled as 'val', 'default', 'data') inside an array service definition, surfacing when the service is resolved. Message reads: "Service 'value' is required in parameter on position N".
Common situations: Copy-pasting a 'service' argument and changing the type but forgetting the companion key, renaming keys, or passing nested arrays that were flattened somewhere (config loading, environment-specific overrides) so 'value' got lost.
Related errors
- Argument at position {} must have a type
- Service '{}' 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/1bab7e132de63a7f.
Report an issue: GitHub.