Skip to content

PHP equality comparison between messages always returns true #7650

Closed
@haberman

Description

@haberman

Comparing messages (or repeated fields, etc) in PHP always returns true, regardless of the contents:

        $m1 = new TestMessage();
        $m2 = new TestMessage();
        $m3 = new TestMessage();
        $rf1 = new RepeatedField(GPBType::INT32);
        $rf2 = new RepeatedField(GPBType::INT32);

        $rf1[] = 5;

        $m1->setOptionalInt32(1);
        $m2->setOptionalInt32(1);
        $m3->setOptionalInt32(3);

        // These succeed.
        $this->assertTrue($m1 == $m2);
        $this->assertFalse($m1 == $rf1);  // Mixing types

        // These fail.
        $this->assertFalse($m1 == $m3);
        $this->assertFalse($rf1 == $rf2);

This is true for the C extension (haven't tested pure-PHP).

Should we change this? Should equality compare contents? Should it be a deep comparison? We should provide answers to these questions and possibly change/fix the existing behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions