-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Throw an exception if unknown parameter passed to a method #96
Comments
This check should only be performed when validation is enabled. |
@vjik I'm not agree with you. It's misconfiguration: when you try to set a non-existent constructor parameter, container should throw an exception. Instead it passes a value to a random existent parameter. This behavior is not intuitive. It leads to bugs, which are very difficult to solve. // Container definition
Foo::class => [
'__construct()' => ['baz' => true],
],
// Direct object creation
new Foo(baz: true); |
That's not how container works. Currently, if you pass a non-existent argument, then it will be ignored. I mistakenly thought, that for implementation we will need to use extra reflection (what leads to a decrease in performance), but no. Add compare count used arguments here is enough. Seems, it is cheap operation.
It's good idea. But won't it be too long even for the development environment? Theoretically we can make it as separate method, and then use it in CI. |
What steps will reproduce the problem?
What is the expected result?
Exception with message, like:
Unknown parameter $baz in Foo::__construct() method. Available paraemeters: $bar
What do you get instead?
New instance of
Foo
with wrongBar
Additional info
The text was updated successfully, but these errors were encountered: