-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Passing a single argument to the QueryBuilder::where() method using named arguments #11253
Comments
You cannot target a variadic parameter with named arguments. That's a limitation of PHP and we can't do much about it. The best we could do here is to throw if we detect unexpected named arguments in |
Sorry, but PHP doesn't prohibit the use of named arguments in conjunction with variadic parameter, as long as only one argument is passed at a time. Due to the fact that only one argument is being used, this piece of code is functioning properly. <?php
declare(strict_types=1);
function foo(mixed ...$variadic): void
{
var_dump($variadic);
}
foo(variadic: 'some'); Calling the |
I didn't say that it prohibits it. I said, it doesn't support it.
It's not and you can see that in the output. You're not targeting the So, your example code does something, but clearly not what you think it would.
Be my guest. 🙂 |
It seems that we misunderstood each other due to my poor English :( Thanks. |
If a method has a variadic signature, you can (in addition to the mandatory parameters) pass any number of ordered or named arguments you like to that method. The question is, does it make sense semantically and what do you expect to happen when you do that? Just because you can, does it mean you should? Your expectation was:
I'm disputing that because we never documented that we would expect arbitrary named arguments on this method. I understand that the error message is more of the garbage-in-garbage-out type and we can certainly improve that. But if we do, it will still be an error, that's for sure. |
see #11260 |
This will really help improve the DX and help prevent possible problems if we are expecting to receive the value of an argument in the form of a |
Bug Report
Summary
Hello there! When we try to call the
QueryBuilder::where()
method using a named argument, we encounter an issue with accessing an undefined array key. As a result, we get a "Warning: Undefined array key 0". The problem occurs because the value of the argument is an associative array.orm/src/QueryBuilder.php
Line 954 in 9acc70d
Current behavior
Warning: Undefined array key 0
How to reproduce
Сall the
QueryBuilder::where()
method using a named argument:Expected behavior
The method worked without errors.
The text was updated successfully, but these errors were encountered: