-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Labels
BugDependencyInjectionHelp wantedIssues and PRs which are looking for volunteers to complete them.Issues and PRs which are looking for volunteers to complete them.Status: Needs Review
Description
Symfony version(s) affected: 4.3.4
Description
When binding arguments with a type, types should be valid if no typehint is used for the constructor argument.
How to reproduce
class PhoneNumberNormalizer implements NormalizerInterface, DenormalizerInterface
{
public function __construct(PhoneNumberUtil $phoneNumberUtil, $region = PhoneNumberUtil::UNKNOWN_REGION)
{
// ...
}
}
register it like:
App\PhoneNumberNormalizer:
bind:
string $region: 'DE'
tags:
- { name: serializer.normalizer, priority: 100 }
will raise an error:
A binding is configured for an argument of type "string" named "$region" for service "Misd
App\PhoneNumberNormalizer" in file "/Users/oskar.stark/dev/backend/config/services.yaml", but no corresponding argument has been found. It may be unused and should be removed, or it may have a typo.
Workaround
App\PhoneNumberNormalizer:
bind:
- string $region: 'DE'
+ $region: 'DE'
tags:
- { name: serializer.normalizer, priority: 100 }
Removing the string
typehint on the binding fixes the problem.
For me using string
here, if the argument itself has no typehint in the constructor is fine.
WDYT?
Metadata
Metadata
Assignees
Labels
BugDependencyInjectionHelp wantedIssues and PRs which are looking for volunteers to complete them.Issues and PRs which are looking for volunteers to complete them.Status: Needs Review