-
Notifications
You must be signed in to change notification settings - Fork 15.6k
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
feat(php): improve return typehint when repeatedfield #11734
base: main
Are you sure you want to change the base?
Conversation
// accommodate for edge case with multiple types. | ||
size_t start_pos = type.find('|'); | ||
if (start_pos != std::string::npos) { | ||
type.replace(start_pos, 1, ">|\\Google\\Protobuf\\Internal\\RepeatedField<"); |
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.
Can we use ArrayAccess
instead? RepeatedField
is an internal type and we do not want to expose it to public interfaces.
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 makes sense to me as long as there are no methods of RepeatedField
that we want IDEs to typehint (e.g., we want the users to only see the objects as an array, and NOT as a RepeatedField
).
Also, if we do that, we should also do that for the setter typehints, for consistency. In this case, I think the best approach would be to use []
, such as @return string[]
.
As changes like this will effect most of the files in our repo, making them at the same time would be ideal. If that sounds good to you, I'll update this PR to remove RepeatedField
entirely for both getters and setters, in favor of the type[]
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.
That sounds good to me. The only caveat is that I'm not sure if we support assignment of PHP arrays to repeated fields or not.
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.
Ok sounds good, yes let's remove RepeatedField in getters and setters. If we use type[]
we should be satisfying that by implementing ArrayAccess
, yes?
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.
@haberman yes that's correct! ArrayAccess
will handle anything annotated with type[]
We do!
…On Mon, Feb 13, 2023, 7:55 PM Joshua Haberman ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/google/protobuf/compiler/php/php_generator.cc
<#11734 (comment)>
:
> case FieldDescriptor::TYPE_GROUP: return "null";
default: assert(false); return "";
}
+ if (field->is_repeated()) {
+ // accommodate for edge case with multiple types.
+ size_t start_pos = type.find('|');
+ if (start_pos != std::string::npos) {
+ type.replace(start_pos, 1, ">|\\Google\\Protobuf\\Internal\\RepeatedField<");
That sounds good to me. The only caveat is that I'm not sure if we support
assignment of PHP arrays to repeated fields or not.
—
Reply to this email directly, view it on GitHub
<#11734 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAZMBP6FYCQ4VKRGZVDXXLWXLJXPANCNFSM6AAAAAAUM4NYKM>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
We triage inactive PRs and issues in order to make it easier to find active work. If this PR should remain active, please add a comment. This PR is labeled |
We triage inactive PRs and issues in order to make it easier to find active work. If this PR should remain active or becomes active again, please reopen it. This PR was closed and archived because there has been no new activity in the 14 days since the |
This is kinda bizarre - so if you ignore a PR for long enough you use that as justification to close it? |
The PR is kept open if there are any comments on the issue. It's to gauge whether there is still interest from the author. I'll reopen this one. |
Hi @bshaffer , can you confirm an answer to my most recent question above?
|
It looks like the PR is still using |
@haberman so a few thoughts on this... There are a few issues with typing things as we have now. This depends on the context of. the typehint: Typehinting a setter as
|
What about |
|
Another thought on this is we could typehint the returns as |
I would also like to add that UnaryCall, ServerStreamingCall, ClientStreamingCall and BidiStreamingCall would be nice to type this way too. |
@jontro can you describe a little bit more what you're asking for? This repo is for protobuf, you may be looking for the gRPC repo, where those classes are defined, or the google cloud PHP repo, where the APIs are defined. If you could provide an example, that would be very helpful. |
@bshaffer Sorry for the confusion. Found a corresponding issue in the grpc repo for this in case anyone else is looking grpc/grpc#33431 |
@haberman But We can consider replacing |
@roxblnfk we've decided to move |
30be71e
to
8f518e0
Compare
aaa08d8 seems to have broken all the tests. |
Adds the type of the
RepeatedField
to the PHPDoc, e.g.Whereas before, the
<int>
part was not included.This is the "getter" counterpart for #4533