fluent interface return type vs return self #7193
Comments
as @weierophinney suggestion in my old PRs, it shoud be return self |
@samsonasik @weierophinney |
Folks, |
Not self either... Should we set the actual class name then? That's the most semantically true version... |
$this as documented return type is allowed by phpDocumentor but @Ocramius is right - it's not a type and don't know how others (like IDEs) will interpret this. 'static' should be a better keyword here. |
On 13 Oct 2016 10:09, "Marc Bennewitz" notifications@github.com wrote:
|
@Ocramius The RFC says:
But all IDEs I know and phpDocumentator understand |
So what's what? Should we go with |
ping? What you guys think then? That's a small and boring contribution but could be better for consistency across the codebase. |
@tdutrion @Ocramius I did a bit research for IDE completions and it looks looks like that So the most safest is to write the class name. Thanks |
I did start an update of my previous PR, will continue over the next weeks :) |
The other source to look at for acceptable annotation values is PHPDocumentor. Per the documentation on types:
In the case of fluent interfaces self is almost certainly what we want to use. Further, I'd argue we should only use the class name as a return type if the method will return a new instance. |
@weierophinney Should you discuss this with @marc-mabe, @akrabat and @ezimuel who accepted 3 of the PRs? All arguments so far seem reasonable to me and my take is choose one and stick to it just as for code style, so whatever please you is fine for me :) I am not against changing again, but really do not want to annoy anyone with such a trivial thing... |
When looking in the api documentation of zf2 I found sometimes @return self is used and in other cases @return {nameOfTheClass} is used. Both situations are resulting in the same documentation. But it would be nice if it would be the same for every fluent interface.
The text was updated successfully, but these errors were encountered: