-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
Add "readonly" as a keyword for PHP and add previous classnames to descriptor pool #10041
Add "readonly" as a keyword for PHP and add previous classnames to descriptor pool #10041
Conversation
71f2b49
to
7ed2c26
Compare
Looks like I need to add some of the new test files to the distribution file! Should be an easy fix. |
@haberman This is ready for another test run! |
It seems to be a network problem or something. |
@zeriyoshi I see the following errors:
Could these be what is causing the |
e496be7
to
5f8e6df
Compare
@zeriyoshi okay I fixed it, for some reason in my commit there was an update to the |
"new", fullname, | ||
"old", message->name()); | ||
LegacyReadOnlyGenerateClassFile(file, message, options, generator_context); | ||
} |
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 looks to duplicate the code above. Can you add well named helper?
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.
There are subtle enough differences that I do not think it would be advantageous to add a helper
c581801
to
4f28c5a
Compare
See #10038
This PR adds compatibility for PHP 8.1 by identifying "readonly" as a reserved word, and by adding forwards compatibility for any
ReadOnly
classes generated with a previous protobuf version (see new tests / new test protos).It should be noted that in the past when we added a new keyword, forwards compatibility was not preserved. We only realized it now because we have several libraries (Spanner/Datastore/Firestore) which use the keyword
readonly
for message names.Summary
ReadOnly
a reserved keyword for PHP 8.1protobuf.so
extension as well!BC file for the previously unreserved classnames
In the file
ReadOnly.php
, where there used to generateclass ReadOnly
, there is now the following code to create an alias for the new classname:This ensures that anyone still using the name
Readme
on previous versions of PHP will not be broken.Alias declaration in new class file to the previously unreserved classnames
Likewise, at the bottom of the new
PBReadOnly.php
file/class, we create an alias to the old one:NOTE: The classname "readonly" is still valid, but the syntax for declaring it (e.g.
class ReadOnly {}
) is not. That means that creating an alias for it, and instantiating the class directly, is still valid in PHP 8.1.Previously unreserved classnames
The previously unreserved classnames function the same way as any other type of reserved word, with the exception that they also get added to the descriptor pool. This is to maintain backwards compatibility.
In order for Protobuf to be able to know and handle any messages defined using the previous classname (e.g.
ReadOnly
) for versions of any library that are still using the older versions, we've added the previous names to the descriptor pool in both the native PHP and the C-extension implementations.