Skip to content
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 missing hasOneof method to check presence of oneof fields #8003

Conversation

anight
Copy link
Contributor

@anight anight commented Nov 3, 2020

Possible solution for #8001 and #7961

test.proto:

syntax = "proto3";
package Test;
message Test {
        oneof O {
                int32 A = 1;
                int32 B = 2;
        }
}

test.php:

<?php
        dl('protobuf.so');
        require_once './vendor/autoload.php';
        $t = new Test\Test();
        print_r($t->hasB() === false);
?>

Output:

$ php ./test.php
Fatal error: Uncaught Error: Call to undefined method Test\Test::hasOneof() ...

Expected output:

$ php ./test.php
1

@google-cla google-cla bot added the cla: yes label Nov 3, 2020
@anight anight changed the title add missing has<Field>() method for oneof fields add missing hasOneof method to check presence of oneof fields Nov 3, 2020
Copy link
Member

@haberman haberman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, thanks! Just a few small comments.

php/ext/google/protobuf/message.c Outdated Show resolved Hide resolved
*
* @return boolean
*/
PHP_METHOD(Message, hasOneof) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test for this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test looks great, but it might be better to move it into one of the existing test files (I think GeneratedClassTest.php would be a good option). Adding new files is a bit more involved because then the new file has to get added to the Makefile:

https://github.com/protocolbuffers/protobuf/blob/master/Makefile.am#L767-L961

@haberman
Copy link
Member

haberman commented Nov 3, 2020

I kicked off the tests. If you move your new test into an existing file, it should fix the "distcheck" test failure.

@haberman
Copy link
Member

haberman commented Nov 4, 2020

We'd like to cut a branch for our upcoming release today and this fix should definitely go in. Are you planning to push again in the next few hours? If not I may need to adopt this change in a different PR to get it merged.

@haberman
Copy link
Member

haberman commented Nov 4, 2020

Actually let me merge this now and the send a follow-up PR to fix the test failures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants