From 49b44bff2b6257a119f9c6a342d6151c736586b8 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Fri, 4 Aug 2017 16:35:49 -0700 Subject: Fix the bug in php c extension that setting one field can change anotherĀ field's value. (#3455) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix the bug in php c extension that setting one field can change another field's value. The reason is that previously, in c extension, it was assumed that the order that fields were declared in php is the same as the order of fields in upb. This is not true. Now, for every field in upb, we will look up the actual property that is corresponding to the upb field. * Cleanup pull request * Fix indentation * Port to php5 * Port with php7.1 * Port to zts --- php/tests/generated_class_test.php | 13 +++++++++++++ php/tests/memory_leak_test.php | 1 + php/tests/proto/test.proto | 5 +++++ 3 files changed, 19 insertions(+) (limited to 'php/tests') diff --git a/php/tests/generated_class_test.php b/php/tests/generated_class_test.php index 56e3be20..86e68683 100644 --- a/php/tests/generated_class_test.php +++ b/php/tests/generated_class_test.php @@ -13,6 +13,7 @@ use Foo\TestIncludeNamespaceMessage; use Foo\TestIncludePrefixMessage; use Foo\TestMessage; use Foo\TestMessage_Sub; +use Foo\TestReverseFieldOrder; use Php\Test\TestNamespace; class GeneratedClassTest extends TestBase @@ -702,4 +703,16 @@ class GeneratedClassTest extends TestBase $this->assertSame(1, $m->getOptionalInt32()); $this->assertSame(2, $m->getOptionalUInt32()); } + + ######################################################### + # Test Reverse Field Order. + ######################################################### + + public function testReverseFieldOrder() + { + $m = new TestReverseFieldOrder(); + $m->setB("abc"); + $this->assertSame("abc", $m->getB()); + $this->assertNotSame("abc", $m->getA()); + } } diff --git a/php/tests/memory_leak_test.php b/php/tests/memory_leak_test.php index faa1833d..a92694d0 100644 --- a/php/tests/memory_leak_test.php +++ b/php/tests/memory_leak_test.php @@ -21,6 +21,7 @@ require_once('generated/Foo/TestMessage_Sub.php'); require_once('generated/Foo/TestPackedMessage.php'); require_once('generated/Foo/TestPhpDoc.php'); require_once('generated/Foo/TestRandomFieldOrder.php'); +require_once('generated/Foo/TestReverseFieldOrder.php'); require_once('generated/Foo/TestUnpackedMessage.php'); require_once('generated/GPBMetadata/Proto/Test.php'); require_once('generated/GPBMetadata/Proto/TestEmptyPhpNamespace.php'); diff --git a/php/tests/proto/test.proto b/php/tests/proto/test.proto index d81f66f5..a90f3d1d 100644 --- a/php/tests/proto/test.proto +++ b/php/tests/proto/test.proto @@ -187,3 +187,8 @@ message TestRandomFieldOrder { int64 tag13 = 150; string tag14 = 160; } + +message TestReverseFieldOrder { + repeated int32 a = 2; + string b = 1; +} -- cgit v1.2.3