-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Align PSR-5 @method signatures with PHP7 with regard to return types #899
Conversation
Also, incorporate static method support.
proposed/phpdoc.md
Outdated
@@ -1220,18 +1220,19 @@ The @method allows a class to know which 'magic' methods are callable. | |||
|
|||
#### Syntax | |||
|
|||
@method [return type] [name]([type] [parameter], [...]) [description] | |||
@method <static|> [name]([type] [parameter], [...])[: return type] [description] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<static|>
seems to be incorrect – according to ABNF. Dunno ABNF in all details, but [static]
looks more appropriate to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah. OK. But shouldnt' [name]
be name
as it is not optional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, at least in this case <name>
would be even better (ABNF 2.1. Rule Naming):
Unlike original BNF, angle brackets ("<", ">") are not required.
However, angle brackets may be used around a rule name whenever their
presence facilitates in discerning the use of a rule name.
But honestly, I cannot really figure out the rules how PSR-5 mixes ABNF and PHP 😕
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just learning this too. I don't know what is more 'correct'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section is not in ABNF. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm hoping someone who knows how to express what I need will be able to add the syntax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@teohhanhui Dunno, if I understand you correctly, but this section uses ABNF.
Thus, either name
or <name>
should be used IMO; and to avoid ambiguity, I'm in favor of <name>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about : @method ["static"] <name>([<type>] [<parameter>] [, ...])[: <returnType>] [description]
Optional literal static'.
Required name.
Optional type and parameter and repeatable.
Optional : return type.
Optional description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's ABNF then it'd be "@method" ["static"] name "(" ...
where name
is a non-terminal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which brings us back to the issue:
But honestly, I cannot really figure out the rules how PSR-5 mixes ABNF and PHP 😕
Obviously the square brackets in @method [name](…) [description]
have different meaning – or is name
really optional – or is description
mandatory?
IMO, an appropriate solution would look something like:
@method [static] <name>([<parameter-list>])[: <type>] [<description>]
Where square brackets ([
and ]
) enclose optional elements, and angle brackets (<
and >
) denote ABNF non-terminals.
+1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Hello @michaelcullum. Wondering if you have any suggestions on this as you are the 'required approver'. |
It needs the PSR-5 team to approve, it just defaults to me when nobody is in that team. We need to setup a PSR-5 WG with @mvriel. |
The change itself makes perfect sense so I think it has a big chance to be merged. |
I've sent an email to @mvriel. Not sure if there's anything else I can do at this stage. |
I am putting together a WG to get PSR-5 moving again - would be happy if anyone here would like to join. |
@GeeH if someone is interested in joining the WG, how would one proceed? |
Ideally reply to the thread on the FIG mailing list - I'll post more info
here soon.
…On Wed, 12 Jul 2017 at 08:58 SpacePossum ***@***.***> wrote:
@GeeH <https://github.com/geeh> if someone is interested in joining the
WG, how would one proceed?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#899 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAlcAOdVwjNqFlqFvfzxNymg2vdnZPKUks5sNHy6gaJpZM4McYyT>
.
|
If you would like to be involved in the working group, please post here https://groups.google.com/forum/#!topic/php-fig/bcV4KXIW6dQ |
Thanks @GeeH I've put my hand up. :) |
My proposal for supporting multiple types in DocBook has been accepted (with amendments) into the DocBook standard. [1], [2], [3]. I'm now looking at getting the PHP Documentation rendering tools to output the PHP 7 syntax for function and method signatures. This may provide a review of the rfc for union types in PHP [4]. In the meantime, is there anyone ready, willing, able to actually move PSR-5 forward a little in this regard. I know it is a tiny change, but even having it accepted into the standard would allow for additional tooling to start the task of getting things uptodate. [1] docbook/docbook#91 |
I'm discussing with the phpDocumentor team about the feasibility of deprecating the old syntax in favor of this new syntax, as I think the parser should be able to distinguish between the two. I've also broached the subject with the WG. Any folks from the IDEs: feedback here would be most useful. |
Note We don't have metrics on how widely it is now used in codebases out there. |
While automatic migration is relatively easy... I personally fail to see the real benefit of changing @method syntax for EVERYBODY, instead of only those wanting '@method static'. Much easier change would be '@method-static', as '@property-read'. Lets be realistic - the old syntax will be out there for .. AGES. Even if we only generate new syntax and all major frameworks update.. we stuck with all implementations still supporting old syntax. Please think twice about existing users. Perhaps working on commercial software and dealing with paying customers complains biases me too much... But such a change "just for sake of consistency" reminds me of lot of rollbacks I personally had to do. Also, being too disruptive may reduce chances of this PSR to be approved. Lets try to find the middle way. |
I'm mainly swayed by this argument based on the matching return type syntax of PHP7. |
Maybe a middle ground here is to allow an optional EDIT: Eclipse PDT (Oxygen) already allows for this: RE-EDIT: I see now this matches the 2014 addition that @neuro159 mentioned earlier about PhpStorm. |
With modern tooling, converting the inconsistent style to match PHP 7's syntax should make this a non-issue. There are many tools that can hook into GitHub and other repos that will push the changes quite happily as a pull request. I suppose another way to look at this is what SHOULD the standard be? |
@ashnazg, the ambiguity is with
|
I actually have the metrics (computed based on top 1000 packages on packagist).
So the |
So, with that analysis, having tools like PHPCS to fix it to PSR-5 would be relatively simple. @neuro159 With any change, there's resistance. That's fair. Every point has to be argued and an agreement reached. But the "that's how we've always done it" position is problematic in that it can be used to resist all change. For all those new developers coming to PHP in the next decade, why are we forcing 3 different and incompatible syntaxes on them for what should/could be an easy replacement. In a decade's time, if unchanged, we'll have more developers and more code not matching. The benefit's aren't just about "consistency". If a new developer comes to the PHP documentation and sees one syntax for the functions and methods and tries to write that in their code, it'll fail. If they try to use the docblock syntax, their code will fail. How is this of any benefit? Tooling can fix this. Certainly reaching out to the IDEs would be extremely useful. I'm only a user of PHPStorm, but I can certainly put a request for some comments out there. https://youtrack.jetbrains.com/issue/WI-42107 |
I just was saying that It will take me a day to support this, with inspection and auto converter in PhpStorm, its NOT A PROBLEM for IDE. (thanks for request :) IMO you adding NO value (except aesthetics) to any of those people (those 6% who use static know how it works anyway) and this is the problem. |
@rquadling New syntax cannot resolve ambiguity. It can only create new one. Ambiguity can only be resolved by introducing a resolution rule or by breaking compatibility. I'm not actually sure at all, what you're proposing. For example https://youtrack.jetbrains.com/issue/WI-42107 mentions that the return type declaration is optional. Is that an oversight? Or is that something you are actually proposing? Can you explicitly specify what conflict resolution rules and what breaking changes are you proposing? |
If php/phd#17 does get accepted, I think it gives this PR a bit more strength. To reiterate, I like this change not so much for resolving the |
What change? Can you explain to me what is actually being proposed? You cannot just propose new stuff without proposing how to handle the old stuff. |
@JanTvrdik : what's being proposed is that the token positions in the Old way: If a return type is given, it now comes after the function name, delimited by colon... just like PHP7 return types are written on the function signature. If a scope modifier exists, it is now the only thing to expect between the tag and the function name. That is the change being proposed. One provided rationale for the change has been the In my discussions within the phpDocumentor team, we're thinking we can successfully deal with recognizing both the old and new formats, and treating the old format as "deprecated". I get the feeling from @neuro159 's comments that IDE support wouldn't be complicated either. Also, as @rquadling has mentioned repeatedly, updating old code is likely feasible via code sniffing CS fixers. |
There are grammar conflicts, i.e. it cannot be done. That's why I'm asking about the grammar conflict resolution rules and the BC break impact. Specifically based on your explanation of what is being proposed (and me guessing what does this mean from grammar point of view), at least the following stuff will be broken due to grammar conflicts if this proposal is accepted.
|
Deprecation of the old format would be of the "best effort" type, as opposed to "handles all cases":
I'm not arguing that all possible permutations of both syntaxes be guaranteed. For your three examples, I would expect these responses:
|
Rereading this with fresh eyes... if there's no consensus on changing the |
@ashnazg Can't we just require explicit return type for static methods? i.e. the syntax would be
(That's what PHPStan currently does) |
@JanTvrdik yes, that would be a viable option to solve the |
It seems like php/phd#17 might be close to being merged. If it does, then I might look at doing a Google survey to see how much interest there is in changing to @rquadling 's original request for PHP7 return syntax. If there's mostly pushback to keep the existing |
Note to self: this PR would have to be updated due to the split into PSR-5/PSR-19. |
As much as I'd like this change, I need to decline it for PSR-19 due to level of BC. Note that I won't forget it, though, when working on a superceding PSR that adds new concepts (generics et al) later on. |
As of 15th November, the PHP Documentation is now rendered closer to the standard format : http://docs.php.net/manual/en/function.curl-init.php as an example. |
Currently, the placement of the return type does not match that of PHP7.
For a new developer, this would seem 'wrong' as there are now 2 different signatures for methods.
In addition, allows for the documentation to support static methods that are processed by
__callStatic()
.And finally, this change removes the ambiguity where a method may be one of two;
Is
getString()
a static method returning void, or a regular method returning a static instance?By having the scope and return type separated, the ambiguity is removed.