Replies: 2 comments 3 replies
-
I think it's a great Idea but, PhpStorm for example does handle it correctly, but also shows an error in the second @method definition with the same name. Not sure if that's wise, using an unsupported way of documentation? |
Beta Was this translation helpful? Give feedback.
2 replies
-
In php 8 it is possible to use named arguments.
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Consider the method
\Illuminate\Database\Eloquent\Builder::where
.It can be invoked as
where('name', 'John Doe')
andwhere('name', '<>', 'John Doe')
but its signature iswhere($column, $operator = null, $value = null, $boolean = 'and')
.So in the first call, it looks like

'John Doe'
is anoperator
, but by semantics, it's avalue
. For the IDE, it's impossible to figure out this change of the meaning, so it shows an incorrect hint:Since PHP doesn't support overloading in the userland, there is no way to define a second method with the correct signature, so the only way to do this is via PHPDoc. Since there is no unique tag for such a situation, I suggest using
@method
.So for the
where
method, we can add the following annotation:@method where(\Closure|array|string|\Illuminate\Database\Query\Expression $column, mixed $value, string $boolean='and')
The annotation will clearly specify the semantics of the second argument for the
where
method.The original request in PhpStorm issue tracker: https://youtrack.jetbrains.com/issue/WI-67614
PhpStorm Team
Beta Was this translation helpful? Give feedback.
All reactions