aboutsummaryrefslogtreecommitdiff
path: root/php
diff options
context:
space:
mode:
Diffstat (limited to 'php')
-rw-r--r--php/ext/google/protobuf/encode_decode.c2
-rw-r--r--php/ext/google/protobuf/map.c93
-rw-r--r--php/ext/google/protobuf/message.c8
-rw-r--r--php/ext/google/protobuf/package.xml35
-rw-r--r--php/ext/google/protobuf/protobuf.c2
-rw-r--r--php/ext/google/protobuf/protobuf.h19
-rw-r--r--php/ext/google/protobuf/storage.c37
-rw-r--r--php/phpunit.xml1
-rw-r--r--php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php1
-rw-r--r--php/src/Google/Protobuf/Internal/DescriptorProto.php19
-rw-r--r--php/src/Google/Protobuf/Internal/DescriptorProto_ExtensionRange.php1
-rw-r--r--php/src/Google/Protobuf/Internal/DescriptorProto_ReservedRange.php1
-rw-r--r--php/src/Google/Protobuf/Internal/EnumDescriptorProto.php5
-rw-r--r--php/src/Google/Protobuf/Internal/EnumOptions.php3
-rw-r--r--php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php3
-rw-r--r--php/src/Google/Protobuf/Internal/EnumValueOptions.php3
-rw-r--r--php/src/Google/Protobuf/Internal/FieldDescriptorProto.php3
-rw-r--r--php/src/Google/Protobuf/Internal/FieldOptions.php3
-rw-r--r--php/src/Google/Protobuf/Internal/FileDescriptorProto.php19
-rw-r--r--php/src/Google/Protobuf/Internal/FileDescriptorSet.php3
-rw-r--r--php/src/Google/Protobuf/Internal/FileOptions.php36
-rw-r--r--php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php3
-rw-r--r--php/src/Google/Protobuf/Internal/GeneratedCodeInfo_Annotation.php3
-rw-r--r--php/src/Google/Protobuf/Internal/MapFieldIter.php5
-rw-r--r--php/src/Google/Protobuf/Internal/MessageOptions.php3
-rw-r--r--php/src/Google/Protobuf/Internal/MethodDescriptorProto.php3
-rw-r--r--php/src/Google/Protobuf/Internal/MethodOptions.php3
-rw-r--r--php/src/Google/Protobuf/Internal/OneofDescriptorProto.php3
-rw-r--r--php/src/Google/Protobuf/Internal/OneofOptions.php3
-rw-r--r--php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php5
-rw-r--r--php/src/Google/Protobuf/Internal/ServiceOptions.php3
-rw-r--r--php/src/Google/Protobuf/Internal/SourceCodeInfo.php3
-rw-r--r--php/src/Google/Protobuf/Internal/SourceCodeInfo_Location.php7
-rw-r--r--php/src/Google/Protobuf/Internal/UninterpretedOption.php3
-rw-r--r--php/src/Google/Protobuf/Internal/UninterpretedOption_NamePart.php1
-rw-r--r--php/tests/array_test.php36
-rw-r--r--php/tests/encode_decode_test.php838
-rw-r--r--php/tests/generated_service_test.php110
-rw-r--r--php/tests/map_field_test.php34
-rw-r--r--php/tests/memory_leak_test.php1
-rw-r--r--php/tests/proto/test.proto6
-rw-r--r--php/tests/proto/test_service.proto18
-rw-r--r--php/tests/proto/test_service_namespace.proto13
-rwxr-xr-xphp/tests/test.sh2
44 files changed, 891 insertions, 512 deletions
diff --git a/php/ext/google/protobuf/encode_decode.c b/php/ext/google/protobuf/encode_decode.c
index b07abfa7..ef3d4cf6 100644
--- a/php/ext/google/protobuf/encode_decode.c
+++ b/php/ext/google/protobuf/encode_decode.c
@@ -474,7 +474,7 @@ static void map_slot_init(void* memory, upb_fieldtype_t type, zval* cache) {
*(zval***)memory = holder;
#else
*(zval**)memory = cache;
- // PHP_PROTO_ZVAL_STRINGL(*(zval**)memory, "", 0, 1);
+ PHP_PROTO_ZVAL_STRINGL(*(zval**)memory, "", 0, 1);
#endif
break;
}
diff --git a/php/ext/google/protobuf/map.c b/php/ext/google/protobuf/map.c
index a5d48446..4a524864 100644
--- a/php/ext/google/protobuf/map.c
+++ b/php/ext/google/protobuf/map.c
@@ -143,6 +143,7 @@ static zend_function_entry map_field_methods[] = {
PHP_ME(MapField, offsetSet, arginfo_offsetSet, ZEND_ACC_PUBLIC)
PHP_ME(MapField, offsetUnset, arginfo_offsetGet, ZEND_ACC_PUBLIC)
PHP_ME(MapField, count, arginfo_void, ZEND_ACC_PUBLIC)
+ PHP_ME(MapField, getIterator, arginfo_void, ZEND_ACC_PUBLIC)
ZEND_FE_END
};
@@ -156,7 +157,10 @@ static void map_field_write_dimension(zval *object, zval *key,
// -----------------------------------------------------------------------------
zend_class_entry* map_field_type;
+zend_class_entry* map_field_iter_type;
+
zend_object_handlers* map_field_handlers;
+zend_object_handlers* map_field_iter_handlers;
static void map_begin_internal(Map *map, MapIter *iter) {
iter->self = map;
@@ -231,8 +235,8 @@ PHP_PROTO_OBJECT_CREATE_END(Map, map_field)
// Init class entry.
PHP_PROTO_INIT_CLASS_START("Google\\Protobuf\\Internal\\MapField", Map,
map_field)
-zend_class_implements(map_field_type TSRMLS_CC, 2, spl_ce_ArrayAccess,
- spl_ce_Countable);
+zend_class_implements(map_field_type TSRMLS_CC, 3, spl_ce_ArrayAccess,
+ zend_ce_aggregate, spl_ce_Countable);
map_field_handlers->write_dimension = map_field_write_dimension;
map_field_handlers->get_gc = map_field_get_gc;
PHP_PROTO_INIT_CLASS_END
@@ -444,6 +448,15 @@ PHP_METHOD(MapField, count) {
RETURN_LONG(upb_strtable_count(&intern->table));
}
+PHP_METHOD(MapField, getIterator) {
+ CREATE_OBJ_ON_ALLOCATED_ZVAL_PTR(return_value,
+ map_field_iter_type);
+
+ Map *intern = UNBOX(Map, getThis());
+ MapIter *iter = UNBOX(MapIter, return_value);
+ map_begin(getThis(), iter TSRMLS_CC);
+}
+
// -----------------------------------------------------------------------------
// Map Iterator
// -----------------------------------------------------------------------------
@@ -470,3 +483,79 @@ upb_value map_iter_value(MapIter *iter, int *len) {
*len = native_slot_size(iter->self->value_type);
return upb_strtable_iter_value(&iter->it);
}
+
+// -----------------------------------------------------------------------------
+// MapFieldIter methods
+// -----------------------------------------------------------------------------
+static zend_function_entry map_field_iter_methods[] = {
+ PHP_ME(MapFieldIter, rewind, arginfo_void, ZEND_ACC_PUBLIC)
+ PHP_ME(MapFieldIter, current, arginfo_void, ZEND_ACC_PUBLIC)
+ PHP_ME(MapFieldIter, key, arginfo_void, ZEND_ACC_PUBLIC)
+ PHP_ME(MapFieldIter, next, arginfo_void, ZEND_ACC_PUBLIC)
+ PHP_ME(MapFieldIter, valid, arginfo_void, ZEND_ACC_PUBLIC)
+ ZEND_FE_END
+};
+
+// -----------------------------------------------------------------------------
+// MapFieldIter creation/desctruction
+// -----------------------------------------------------------------------------
+
+// Define object free method.
+PHP_PROTO_OBJECT_FREE_START(MapIter, map_field_iter)
+PHP_PROTO_OBJECT_FREE_END
+
+PHP_PROTO_OBJECT_DTOR_START(MapIter, map_field_iter)
+PHP_PROTO_OBJECT_DTOR_END
+
+// Define object create method.
+PHP_PROTO_OBJECT_CREATE_START(MapIter, map_field_iter)
+intern->self = NULL;
+PHP_PROTO_OBJECT_CREATE_END(MapIter, map_field_iter)
+
+// Init class entry.
+PHP_PROTO_INIT_CLASS_START("Google\\Protobuf\\Internal\\MapFieldIter",
+ MapIter, map_field_iter)
+zend_class_implements(map_field_iter_type TSRMLS_CC, 1, zend_ce_iterator);
+PHP_PROTO_INIT_CLASS_END
+
+// -----------------------------------------------------------------------------
+// PHP MapFieldIter Methods
+// -----------------------------------------------------------------------------
+
+PHP_METHOD(MapFieldIter, rewind) {
+ MapIter *intern = UNBOX(MapIter, getThis());
+ map_begin_internal(intern->self, intern);
+}
+
+PHP_METHOD(MapFieldIter, current) {
+ MapIter *intern = UNBOX(MapIter, getThis());
+ Map *map_field = intern->self;
+
+ int value_length = 0;
+ upb_value value = map_iter_value(intern, &value_length);
+
+ void* mem = upb_value_memory(&value);
+ native_slot_get_by_array(map_field->value_type, mem,
+ ZVAL_PTR_TO_CACHED_PTR(return_value) TSRMLS_CC);
+}
+
+PHP_METHOD(MapFieldIter, key) {
+ MapIter *intern = UNBOX(MapIter, getThis());
+ Map *map_field = intern->self;
+
+ int key_length = 0;
+ const char* key = map_iter_key(intern, &key_length);
+
+ native_slot_get_by_map_key(map_field->key_type, key, key_length,
+ ZVAL_PTR_TO_CACHED_PTR(return_value) TSRMLS_CC);
+}
+
+PHP_METHOD(MapFieldIter, next) {
+ MapIter *intern = UNBOX(MapIter, getThis());
+ map_next(intern);
+}
+
+PHP_METHOD(MapFieldIter, valid) {
+ MapIter *intern = UNBOX(MapIter, getThis());
+ RETURN_BOOL(!map_done(intern));
+}
diff --git a/php/ext/google/protobuf/message.c b/php/ext/google/protobuf/message.c
index b8ef9fc0..254640c7 100644
--- a/php/ext/google/protobuf/message.c
+++ b/php/ext/google/protobuf/message.c
@@ -115,7 +115,11 @@ static void message_set_property(zval* object, zval* member, zval* value,
return;
}
+#if PHP_MAJOR_VERSION < 7 || (PHP_MAJOR_VERSION == 7 && PHP_MINOR_VERSION == 0)
if (Z_OBJCE_P(object) != EG(scope)) {
+#else
+ if (Z_OBJCE_P(object) != zend_get_executed_scope()) {
+#endif
// User cannot set property directly (e.g., $m->a = 1)
zend_error(E_USER_ERROR, "Cannot access private property.");
return;
@@ -145,7 +149,11 @@ static zval* message_get_property(zval* object, zval* member, int type,
return PHP_PROTO_GLOBAL_UNINITIALIZED_ZVAL;
}
+#if PHP_MAJOR_VERSION < 7 || (PHP_MAJOR_VERSION == 7 && PHP_MINOR_VERSION == 0)
if (Z_OBJCE_P(object) != EG(scope)) {
+#else
+ if (Z_OBJCE_P(object) != zend_get_executed_scope()) {
+#endif
// User cannot get property directly (e.g., $a = $m->a)
zend_error(E_USER_ERROR, "Cannot access private property.");
return PHP_PROTO_GLOBAL_UNINITIALIZED_ZVAL;
diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml
index a2a8e066..20a45bc6 100644
--- a/php/ext/google/protobuf/package.xml
+++ b/php/ext/google/protobuf/package.xml
@@ -13,7 +13,7 @@
<date>2017-01-13</date>
<time>16:06:07</time>
<version>
- <release>3.3.0</release>
+ <release>3.3.2</release>
<api>3.3.0</api>
</version>
<stability>
@@ -40,6 +40,7 @@ GA release.
<file baseinstalldir="/" name="upb.h" role="src" />
<file baseinstalldir="/" name="utf8.c" role="src" />
<file baseinstalldir="/" name="utf8.h" role="src" />
+ <file baseinstalldir="/" name="LICENSE" role="doc" />
</dir>
</contents>
<dependencies>
@@ -103,5 +104,37 @@ Second alpha release.
GA release.
</notes>
</release>
+ <release>
+ <version>
+ <release>3.3.1</release>
+ <api>3.3.0</api>
+ </version>
+ <stability>
+ <release>stable</release>
+ <api>stable</api>
+ </stability>
+ <date>2017-05-08</date>
+ <time>15:33:07</time>
+ <license uri="https://opensource.org/licenses/BSD-3-Clause">3-Clause BSD License</license>
+ <notes>
+GA release.
+ </notes>
+ </release>
+ <release>
+ <version>
+ <release>3.3.2</release>
+ <api>3.3.0</api>
+ </version>
+ <stability>
+ <release>stable</release>
+ <api>stable</api>
+ </stability>
+ <date>2017-06-21</date>
+ <time>15:33:07</time>
+ <license uri="https://opensource.org/licenses/BSD-3-Clause">3-Clause BSD License</license>
+ <notes>
+GA release.
+ </notes>
+ </release>
</changelog>
</package>
diff --git a/php/ext/google/protobuf/protobuf.c b/php/ext/google/protobuf/protobuf.c
index 6a848b27..5de9cfe9 100644
--- a/php/ext/google/protobuf/protobuf.c
+++ b/php/ext/google/protobuf/protobuf.c
@@ -189,6 +189,7 @@ static PHP_RSHUTDOWN_FUNCTION(protobuf) {
static PHP_MINIT_FUNCTION(protobuf) {
map_field_init(TSRMLS_C);
+ map_field_iter_init(TSRMLS_C);
repeated_field_init(TSRMLS_C);
repeated_field_iter_init(TSRMLS_C);
gpb_type_init(TSRMLS_C);
@@ -206,6 +207,7 @@ static PHP_MSHUTDOWN_FUNCTION(protobuf) {
PEFREE(repeated_field_handlers);
PEFREE(repeated_field_iter_handlers);
PEFREE(map_field_handlers);
+ PEFREE(map_field_iter_handlers);
return 0;
}
diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h
index 406a09a5..33787e86 100644
--- a/php/ext/google/protobuf/protobuf.h
+++ b/php/ext/google/protobuf/protobuf.h
@@ -37,7 +37,7 @@
#include "upb.h"
#define PHP_PROTOBUF_EXTNAME "protobuf"
-#define PHP_PROTOBUF_VERSION "3.3.0"
+#define PHP_PROTOBUF_VERSION "3.3.2"
#define MAX_LENGTH_OF_INT64 20
#define SIZEOF_INT64 8
@@ -373,6 +373,7 @@ struct MessageLayout;
struct RepeatedField;
struct RepeatedFieldIter;
struct Map;
+struct MapIter;
struct Oneof;
typedef struct DescriptorPool DescriptorPool;
@@ -385,6 +386,7 @@ typedef struct MessageLayout MessageLayout;
typedef struct RepeatedField RepeatedField;
typedef struct RepeatedFieldIter RepeatedFieldIter;
typedef struct Map Map;
+typedef struct MapIter MapIter;
typedef struct Oneof Oneof;
// -----------------------------------------------------------------------------
@@ -400,6 +402,7 @@ void enum_descriptor_init(TSRMLS_D);
void descriptor_pool_init(TSRMLS_D);
void gpb_type_init(TSRMLS_D);
void map_field_init(TSRMLS_D);
+void map_field_iter_init(TSRMLS_D);
void repeated_field_init(TSRMLS_D);
void repeated_field_iter_init(TSRMLS_D);
void util_init(TSRMLS_D);
@@ -637,7 +640,7 @@ bool native_slot_set(upb_fieldtype_t type, const zend_class_entry* klass,
bool native_slot_set_by_array(upb_fieldtype_t type,
const zend_class_entry* klass, void* memory,
zval* value TSRMLS_DC);
-void native_slot_init(upb_fieldtype_t type, void* memory, void* cache);
+void native_slot_init(upb_fieldtype_t type, void* memory, CACHED_VALUE* cache);
// For each property, in order to avoid conversion between the zval object and
// the actual data type during parsing/serialization, the containing message
// object use the custom memory layout to store the actual data type for each
@@ -659,6 +662,7 @@ void native_slot_get_default(upb_fieldtype_t type,
// -----------------------------------------------------------------------------
extern zend_object_handlers* map_field_handlers;
+extern zend_object_handlers* map_field_iter_handlers;
PHP_PROTO_WRAP_OBJECT_START(Map)
upb_fieldtype_t key_type;
@@ -667,10 +671,10 @@ PHP_PROTO_WRAP_OBJECT_START(Map)
upb_strtable table;
PHP_PROTO_WRAP_OBJECT_END
-typedef struct {
+PHP_PROTO_WRAP_OBJECT_START(MapIter)
Map* self;
upb_strtable_iter it;
-} MapIter;
+PHP_PROTO_WRAP_OBJECT_END
void map_begin(zval* self, MapIter* iter TSRMLS_DC);
void map_next(MapIter* iter);
@@ -709,6 +713,13 @@ PHP_METHOD(MapField, offsetGet);
PHP_METHOD(MapField, offsetSet);
PHP_METHOD(MapField, offsetUnset);
PHP_METHOD(MapField, count);
+PHP_METHOD(MapField, getIterator);
+
+PHP_METHOD(MapFieldIter, rewind);
+PHP_METHOD(MapFieldIter, current);
+PHP_METHOD(MapFieldIter, key);
+PHP_METHOD(MapFieldIter, next);
+PHP_METHOD(MapFieldIter, valid);
// -----------------------------------------------------------------------------
// Repeated Field.
diff --git a/php/ext/google/protobuf/storage.c b/php/ext/google/protobuf/storage.c
index 6318f88c..6c789bcb 100644
--- a/php/ext/google/protobuf/storage.c
+++ b/php/ext/google/protobuf/storage.c
@@ -210,7 +210,7 @@ bool native_slot_set_by_array(upb_fieldtype_t type,
return true;
}
-void native_slot_init(upb_fieldtype_t type, void* memory, void* cache) {
+void native_slot_init(upb_fieldtype_t type, void* memory, CACHED_VALUE* cache) {
zval* tmp = NULL;
switch (type) {
case UPB_TYPE_FLOAT:
@@ -224,6 +224,9 @@ void native_slot_init(upb_fieldtype_t type, void* memory, void* cache) {
break;
case UPB_TYPE_STRING:
case UPB_TYPE_BYTES:
+ DEREF(memory, CACHED_VALUE*) = cache;
+ ZVAL_EMPTY_STRING(CACHED_PTR_TO_ZVAL_PTR(cache));
+ break;
case UPB_TYPE_MESSAGE:
DEREF(memory, CACHED_VALUE*) = cache;
break;
@@ -355,6 +358,19 @@ void native_slot_get_by_array(upb_fieldtype_t type, const void* memory,
}
}
+void native_slot_get_by_map_key(upb_fieldtype_t type, const void* memory,
+ int length, CACHED_VALUE* cache TSRMLS_DC) {
+ switch (type) {
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES: {
+ PHP_PROTO_ZVAL_STRINGL(CACHED_PTR_TO_ZVAL_PTR(cache), memory, length, 1);
+ return;
+ }
+ default:
+ native_slot_get(type, memory, cache TSRMLS_CC);
+ }
+}
+
void native_slot_get_default(upb_fieldtype_t type,
CACHED_VALUE* cache TSRMLS_DC) {
switch (type) {
@@ -608,6 +624,21 @@ void layout_init(MessageLayout* layout, void* storage,
int cache_index = slot_property_cache(layout, storage, field);
CACHED_VALUE* property_ptr = &properties_table[cache_index];
+ // Clean up initial value by generated code. In the generated code of
+ // previous versions, each php field is given an initial value. However, the
+ // order to initialize these fields may not be consistent with the order of
+ // upb fields.
+ if (Z_TYPE_P(CACHED_PTR_TO_ZVAL_PTR(property_ptr)) == IS_STRING) {
+#if PHP_MAJOR_VERSION < 7
+ if (!IS_INTERNED(Z_STRVAL_PP(property_ptr))) {
+ FREE(Z_STRVAL_PP(property_ptr));
+ }
+#else
+ zend_string_release(Z_STR_P(property_ptr));
+#endif
+ }
+ ZVAL_NULL(CACHED_PTR_TO_ZVAL_PTR(property_ptr));
+
if (upb_fielddef_containingoneof(field)) {
memset(memory, 0, NATIVE_SLOT_MAX_SIZE);
*oneof_case = ONEOF_CASE_NONE;
@@ -731,7 +762,7 @@ void layout_set(MessageLayout* layout, MessageHeader* header,
}
}
-static native_slot_merge(const upb_fielddef* field, const void* from_memory,
+static void native_slot_merge(const upb_fielddef* field, const void* from_memory,
void* to_memory PHP_PROTO_TSRMLS_DC) {
upb_fieldtype_t type = upb_fielddef_type(field);
zend_class_entry* ce = NULL;
@@ -788,7 +819,7 @@ static native_slot_merge(const upb_fielddef* field, const void* from_memory,
}
}
-static native_slot_merge_by_array(const upb_fielddef* field, const void* from_memory,
+static void native_slot_merge_by_array(const upb_fielddef* field, const void* from_memory,
void* to_memory PHP_PROTO_TSRMLS_DC) {
upb_fieldtype_t type = upb_fielddef_type(field);
switch (type) {
diff --git a/php/phpunit.xml b/php/phpunit.xml
index 7cb1e2a3..637467be 100644
--- a/php/phpunit.xml
+++ b/php/phpunit.xml
@@ -10,6 +10,7 @@
<file>tests/generated_phpdoc_test.php</file>
<file>tests/map_field_test.php</file>
<file>tests/well_known_test.php</file>
+ <file>tests/generated_service_test.php</file>
</testsuite>
</testsuites>
</phpunit>
diff --git a/php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php b/php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php
index 636a0ad4..1e3c745e 100644
--- a/php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php
+++ b/php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php
@@ -139,6 +139,7 @@ class Descriptor
->optional('cc_generic_services', \Google\Protobuf\Internal\GPBType::BOOL, 16)
->optional('java_generic_services', \Google\Protobuf\Internal\GPBType::BOOL, 17)
->optional('py_generic_services', \Google\Protobuf\Internal\GPBType::BOOL, 18)
+ ->optional('php_generic_services', \Google\Protobuf\Internal\GPBType::BOOL, 19)
->optional('deprecated', \Google\Protobuf\Internal\GPBType::BOOL, 23)
->optional('cc_enable_arenas', \Google\Protobuf\Internal\GPBType::BOOL, 31)
->optional('objc_class_prefix', \Google\Protobuf\Internal\GPBType::STRING, 36)
diff --git a/php/src/Google/Protobuf/Internal/DescriptorProto.php b/php/src/Google/Protobuf/Internal/DescriptorProto.php
index 0fdaecfc..1d6959b7 100644
--- a/php/src/Google/Protobuf/Internal/DescriptorProto.php
+++ b/php/src/Google/Protobuf/Internal/DescriptorProto.php
@@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
-
use Google\Protobuf\Internal\GPBUtil;
/**
@@ -119,7 +118,7 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\FieldDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setField(&$var)
+ public function setField($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FieldDescriptorProto::class);
$this->field = $arr;
@@ -147,7 +146,7 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\FieldDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setExtension(&$var)
+ public function setExtension($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FieldDescriptorProto::class);
$this->extension = $arr;
@@ -175,7 +174,7 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\DescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setNestedType(&$var)
+ public function setNestedType($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto::class);
$this->nested_type = $arr;
@@ -203,7 +202,7 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\EnumDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setEnumType(&$var)
+ public function setEnumType($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\EnumDescriptorProto::class);
$this->enum_type = $arr;
@@ -231,7 +230,7 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\DescriptorProto_ExtensionRange[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setExtensionRange(&$var)
+ public function setExtensionRange($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto_ExtensionRange::class);
$this->extension_range = $arr;
@@ -259,7 +258,7 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\OneofDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setOneofDecl(&$var)
+ public function setOneofDecl($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\OneofDescriptorProto::class);
$this->oneof_decl = $arr;
@@ -287,7 +286,7 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\MessageOptions $var
* @return $this
*/
- public function setOptions(&$var)
+ public function setOptions($var)
{
GPBUtil::checkMessage($var, \Google\Protobuf\Internal\MessageOptions::class);
$this->options = $var;
@@ -315,7 +314,7 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\DescriptorProto_ReservedRange[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setReservedRange(&$var)
+ public function setReservedRange($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto_ReservedRange::class);
$this->reserved_range = $arr;
@@ -349,7 +348,7 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message
* @param string[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setReservedName(&$var)
+ public function setReservedName($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING);
$this->reserved_name = $arr;
diff --git a/php/src/Google/Protobuf/Internal/DescriptorProto_ExtensionRange.php b/php/src/Google/Protobuf/Internal/DescriptorProto_ExtensionRange.php
index bbd34824..51d5d359 100644
--- a/php/src/Google/Protobuf/Internal/DescriptorProto_ExtensionRange.php
+++ b/php/src/Google/Protobuf/Internal/DescriptorProto_ExtensionRange.php
@@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
-
use Google\Protobuf\Internal\GPBUtil;
/**
diff --git a/php/src/Google/Protobuf/Internal/DescriptorProto_ReservedRange.php b/php/src/Google/Protobuf/Internal/DescriptorProto_ReservedRange.php
index 3d613133..b1022d61 100644
--- a/php/src/Google/Protobuf/Internal/DescriptorProto_ReservedRange.php
+++ b/php/src/Google/Protobuf/Internal/DescriptorProto_ReservedRange.php
@@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
-
use Google\Protobuf\Internal\GPBUtil;
/**
diff --git a/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php b/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php
index 6cdaf2df..816fbae5 100644
--- a/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php
+++ b/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php
@@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
-
use Google\Protobuf\Internal\GPBUtil;
/**
@@ -81,7 +80,7 @@ class EnumDescriptorProto extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\EnumValueDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setValue(&$var)
+ public function setValue($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\EnumValueDescriptorProto::class);
$this->value = $arr;
@@ -109,7 +108,7 @@ class EnumDescriptorProto extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\EnumOptions $var
* @return $this
*/
- public function setOptions(&$var)
+ public function setOptions($var)
{
GPBUtil::checkMessage($var, \Google\Protobuf\Internal\EnumOptions::class);
$this->options = $var;
diff --git a/php/src/Google/Protobuf/Internal/EnumOptions.php b/php/src/Google/Protobuf/Internal/EnumOptions.php
index 3c3a9e22..3f598a41 100644
--- a/php/src/Google/Protobuf/Internal/EnumOptions.php
+++ b/php/src/Google/Protobuf/Internal/EnumOptions.php
@@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
-
use Google\Protobuf\Internal\GPBUtil;
/**
@@ -137,7 +136,7 @@ class EnumOptions extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\UninterpretedOption[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setUninterpretedOption(&$var)
+ public function setUninterpretedOption($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
$this->uninterpreted_option = $arr;
diff --git a/php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php b/php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php
index 89d6707f..e363220f 100644
--- a/php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php
+++ b/php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php
@@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
-
use Google\Protobuf\Internal\GPBUtil;
/**
@@ -109,7 +108,7 @@ class EnumValueDescriptorProto extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\EnumValueOptions $var
* @return $this
*/
- public function setOptions(&$var)
+ public function setOptions($var)
{
GPBUtil::checkMessage($var, \Google\Protobuf\Internal\EnumValueOptions::class);
$this->options = $var;
diff --git a/php/src/Google/Protobuf/Internal/EnumValueOptions.php b/php/src/Google/Protobuf/Internal/EnumValueOptions.php
index 3b5c58e4..db8de174 100644
--- a/php/src/Google/Protobuf/Internal/EnumValueOptions.php
+++ b/php/src/Google/Protobuf/Internal/EnumValueOptions.php
@@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
-
use Google\Protobuf\Internal\GPBUtil;
/**
@@ -95,7 +94,7 @@ class EnumValueOptions extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\UninterpretedOption[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setUninterpretedOption(&$var)
+ public function setUninterpretedOption($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
$this->uninterpreted_option = $arr;
diff --git a/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php b/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php
index ae61be47..10c27593 100644
--- a/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php
+++ b/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php
@@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
-
use Google\Protobuf\Internal\GPBUtil;
/**
@@ -418,7 +417,7 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\FieldOptions $var
* @return $this
*/
- public function setOptions(&$var)
+ public function setOptions($var)
{
GPBUtil::checkMessage($var, \Google\Protobuf\Internal\FieldOptions::class);
$this->options = $var;
diff --git a/php/src/Google/Protobuf/Internal/FieldOptions.php b/php/src/Google/Protobuf/Internal/FieldOptions.php
index 157c0f82..3144e670 100644
--- a/php/src/Google/Protobuf/Internal/FieldOptions.php
+++ b/php/src/Google/Protobuf/Internal/FieldOptions.php
@@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
-
use Google\Protobuf\Internal\GPBUtil;
/**
@@ -404,7 +403,7 @@ class FieldOptions extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\UninterpretedOption[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setUninterpretedOption(&$var)
+ public function setUninterpretedOption($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
$this->uninterpreted_option = $arr;
diff --git a/php/src/Google/Protobuf/Internal/FileDescriptorProto.php b/php/src/Google/Protobuf/Internal/FileDescriptorProto.php
index 3b1567d1..9ee222d1 100644
--- a/php/src/Google/Protobuf/Internal/FileDescriptorProto.php
+++ b/php/src/Google/Protobuf/Internal/FileDescriptorProto.php
@@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
-
use Google\Protobuf\Internal\GPBUtil;
/**
@@ -187,7 +186,7 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message
* @param string[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setDependency(&$var)
+ public function setDependency($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING);
$this->dependency = $arr;
@@ -219,7 +218,7 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message
* @param int[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setPublicDependency(&$var)
+ public function setPublicDependency($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32);
$this->public_dependency = $arr;
@@ -253,7 +252,7 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message
* @param int[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setWeakDependency(&$var)
+ public function setWeakDependency($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32);
$this->weak_dependency = $arr;
@@ -285,7 +284,7 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\DescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setMessageType(&$var)
+ public function setMessageType($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto::class);
$this->message_type = $arr;
@@ -313,7 +312,7 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\EnumDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setEnumType(&$var)
+ public function setEnumType($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\EnumDescriptorProto::class);
$this->enum_type = $arr;
@@ -341,7 +340,7 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\ServiceDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setService(&$var)
+ public function setService($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\ServiceDescriptorProto::class);
$this->service = $arr;
@@ -369,7 +368,7 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\FieldDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setExtension(&$var)
+ public function setExtension($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FieldDescriptorProto::class);
$this->extension = $arr;
@@ -397,7 +396,7 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\FileOptions $var
* @return $this
*/
- public function setOptions(&$var)
+ public function setOptions($var)
{
GPBUtil::checkMessage($var, \Google\Protobuf\Internal\FileOptions::class);
$this->options = $var;
@@ -435,7 +434,7 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\SourceCodeInfo $var
* @return $this
*/
- public function setSourceCodeInfo(&$var)
+ public function setSourceCodeInfo($var)
{
GPBUtil::checkMessage($var, \Google\Protobuf\Internal\SourceCodeInfo::class);
$this->source_code_info = $var;
diff --git a/php/src/Google/Protobuf/Internal/FileDescriptorSet.php b/php/src/Google/Protobuf/Internal/FileDescriptorSet.php
index 591e2a81..0b2cf957 100644
--- a/php/src/Google/Protobuf/Internal/FileDescriptorSet.php
+++ b/php/src/Google/Protobuf/Internal/FileDescriptorSet.php
@@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
-
use Google\Protobuf\Internal\GPBUtil;
/**
@@ -44,7 +43,7 @@ class FileDescriptorSet extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\FileDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setFile(&$var)
+ public function setFile($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FileDescriptorProto::class);
$this->file = $arr;
diff --git a/php/src/Google/Protobuf/Internal/FileOptions.php b/php/src/Google/Protobuf/Internal/FileOptions.php
index 2202102b..c2dd5e08 100644
--- a/php/src/Google/Protobuf/Internal/FileOptions.php
+++ b/php/src/Google/Protobuf/Internal/FileOptions.php
@@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
-
use Google\Protobuf\Internal\GPBUtil;
/**
@@ -110,6 +109,11 @@ class FileOptions extends \Google\Protobuf\Internal\Message
private $py_generic_services = false;
private $has_py_generic_services = false;
/**
+ * Generated from protobuf field <code>optional bool php_generic_services = 19 [default = false];</code>
+ */
+ private $php_generic_services = false;
+ private $has_php_generic_services = false;
+ /**
* Is this file deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for everything in the file, or it will be completely ignored; in the very
@@ -549,6 +553,34 @@ class FileOptions extends \Google\Protobuf\Internal\Message
}
/**
+ * Generated from protobuf field <code>optional bool php_generic_services = 19 [default = false];</code>
+ * @return bool
+ */
+ public function getPhpGenericServices()
+ {
+ return $this->php_generic_services;
+ }
+
+ /**
+ * Generated from protobuf field <code>optional bool php_generic_services = 19 [default = false];</code>
+ * @param bool $var
+ * @return $this
+ */
+ public function setPhpGenericServices($var)
+ {
+ GPBUtil::checkBool($var);
+ $this->php_generic_services = $var;
+ $this->has_php_generic_services = true;
+
+ return $this;
+ }
+
+ public function hasPhpGenericServices()
+ {
+ return $this->has_php_generic_services;
+ }
+
+ /**
* Is this file deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for everything in the file, or it will be completely ignored; in the very
@@ -812,7 +844,7 @@ class FileOptions extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\UninterpretedOption[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setUninterpretedOption(&$var)
+ public function setUninterpretedOption($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
$this->uninterpreted_option = $arr;
diff --git a/php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php b/php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php
index 35b47526..ae2ad745 100644
--- a/php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php
+++ b/php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php
@@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
-
use Google\Protobuf\Internal\GPBUtil;
/**
@@ -54,7 +53,7 @@ class GeneratedCodeInfo extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\GeneratedCodeInfo_Annotation[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setAnnotation(&$var)
+ public function setAnnotation($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\GeneratedCodeInfo_Annotation::class);
$this->annotation = $arr;
diff --git a/php/src/Google/Protobuf/Internal/GeneratedCodeInfo_Annotation.php b/php/src/Google/Protobuf/Internal/GeneratedCodeInfo_Annotation.php
index c2e22e89..22ac2337 100644
--- a/php/src/Google/Protobuf/Internal/GeneratedCodeInfo_Annotation.php
+++ b/php/src/Google/Protobuf/Internal/GeneratedCodeInfo_Annotation.php
@@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
-
use Google\Protobuf\Internal\GPBUtil;
/**
@@ -74,7 +73,7 @@ class GeneratedCodeInfo_Annotation extends \Google\Protobuf\Internal\Message
* @param int[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setPath(&$var)
+ public function setPath($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32);
$this->path = $arr;
diff --git a/php/src/Google/Protobuf/Internal/MapFieldIter.php b/php/src/Google/Protobuf/Internal/MapFieldIter.php
index cb707955..88e6c8b2 100644
--- a/php/src/Google/Protobuf/Internal/MapFieldIter.php
+++ b/php/src/Google/Protobuf/Internal/MapFieldIter.php
@@ -91,9 +91,12 @@ class MapFieldIter implements \Iterator
public function key()
{
$key = key($this->container);
- // PHP associative array stores bool as integer for key.
if ($this->key_type === GPBType::BOOL) {
+ // PHP associative array stores bool as integer for key.
return boolval($key);
+ } elseif ($this->key_type === GPBType::STRING) {
+ // PHP associative array stores int string as int for key.
+ return strval($key);
} else {
return $key;
}
diff --git a/php/src/Google/Protobuf/Internal/MessageOptions.php b/php/src/Google/Protobuf/Internal/MessageOptions.php
index 3677ca38..99ff3d0e 100644
--- a/php/src/Google/Protobuf/Internal/MessageOptions.php
+++ b/php/src/Google/Protobuf/Internal/MessageOptions.php
@@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
-
use Google\Protobuf\Internal\GPBUtil;
/**
@@ -311,7 +310,7 @@ class MessageOptions extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\UninterpretedOption[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setUninterpretedOption(&$var)
+ public function setUninterpretedOption($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
$this->uninterpreted_option = $arr;
diff --git a/php/src/Google/Protobuf/Internal/MethodDescriptorProto.php b/php/src/Google/Protobuf/Internal/MethodDescriptorProto.php
index 69c25b69..ccfce2db 100644
--- a/php/src/Google/Protobuf/Internal/MethodDescriptorProto.php
+++ b/php/src/Google/Protobuf/Internal/MethodDescriptorProto.php
@@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
-
use Google\Protobuf\Internal\GPBUtil;
/**
@@ -165,7 +164,7 @@ class MethodDescriptorProto extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\MethodOptions $var
* @return $this
*/
- public function setOptions(&$var)
+ public function setOptions($var)
{
GPBUtil::checkMessage($var, \Google\Protobuf\Internal\MethodOptions::class);
$this->options = $var;
diff --git a/php/src/Google/Protobuf/Internal/MethodOptions.php b/php/src/Google/Protobuf/Internal/MethodOptions.php
index 5b2db776..baa806b7 100644
--- a/php/src/Google/Protobuf/Internal/MethodOptions.php
+++ b/php/src/Google/Protobuf/Internal/MethodOptions.php
@@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
-
use Google\Protobuf\Internal\GPBUtil;
/**
@@ -128,7 +127,7 @@ class MethodOptions extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\UninterpretedOption[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setUninterpretedOption(&$var)
+ public function setUninterpretedOption($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
$this->uninterpreted_option = $arr;
diff --git a/php/src/Google/Protobuf/Internal/OneofDescriptorProto.php b/php/src/Google/Protobuf/Internal/OneofDescriptorProto.php
index 0d4f3bdc..15ff0610 100644
--- a/php/src/Google/Protobuf/Internal/OneofDescriptorProto.php
+++ b/php/src/Google/Protobuf/Internal/OneofDescriptorProto.php
@@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
-
use Google\Protobuf\Internal\GPBUtil;
/**
@@ -76,7 +75,7 @@ class OneofDescriptorProto extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\OneofOptions $var
* @return $this
*/
- public function setOptions(&$var)
+ public function setOptions($var)
{
GPBUtil::checkMessage($var, \Google\Protobuf\Internal\OneofOptions::class);
$this->options = $var;
diff --git a/php/src/Google/Protobuf/Internal/OneofOptions.php b/php/src/Google/Protobuf/Internal/OneofOptions.php
index aa8c934c..e5b4633d 100644
--- a/php/src/Google/Protobuf/Internal/OneofOptions.php
+++ b/php/src/Google/Protobuf/Internal/OneofOptions.php
@@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
-
use Google\Protobuf\Internal\GPBUtil;
/**
@@ -47,7 +46,7 @@ class OneofOptions extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\UninterpretedOption[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setUninterpretedOption(&$var)
+ public function setUninterpretedOption($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
$this->uninterpreted_option = $arr;
diff --git a/php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php b/php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php
index 963cd650..da88e9c4 100644
--- a/php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php
+++ b/php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php
@@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
-
use Google\Protobuf\Internal\GPBUtil;
/**
@@ -81,7 +80,7 @@ class ServiceDescriptorProto extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\MethodDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setMethod(&$var)
+ public function setMethod($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\MethodDescriptorProto::class);
$this->method = $arr;
@@ -109,7 +108,7 @@ class ServiceDescriptorProto extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\ServiceOptions $var
* @return $this
*/
- public function setOptions(&$var)
+ public function setOptions($var)
{
GPBUtil::checkMessage($var, \Google\Protobuf\Internal\ServiceOptions::class);
$this->options = $var;
diff --git a/php/src/Google/Protobuf/Internal/ServiceOptions.php b/php/src/Google/Protobuf/Internal/ServiceOptions.php
index ea649865..3e7214a1 100644
--- a/php/src/Google/Protobuf/Internal/ServiceOptions.php
+++ b/php/src/Google/Protobuf/Internal/ServiceOptions.php
@@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
-
use Google\Protobuf\Internal\GPBUtil;
/**
@@ -95,7 +94,7 @@ class ServiceOptions extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\UninterpretedOption[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setUninterpretedOption(&$var)
+ public function setUninterpretedOption($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
$this->uninterpreted_option = $arr;
diff --git a/php/src/Google/Protobuf/Internal/SourceCodeInfo.php b/php/src/Google/Protobuf/Internal/SourceCodeInfo.php
index 65530586..6ce05ed4 100644
--- a/php/src/Google/Protobuf/Internal/SourceCodeInfo.php
+++ b/php/src/Google/Protobuf/Internal/SourceCodeInfo.php
@@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
-
use Google\Protobuf\Internal\GPBUtil;
/**
@@ -170,7 +169,7 @@ class SourceCodeInfo extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\SourceCodeInfo_Location[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setLocation(&$var)
+ public function setLocation($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\SourceCodeInfo_Location::class);
$this->location = $arr;
diff --git a/php/src/Google/Protobuf/Internal/SourceCodeInfo_Location.php b/php/src/Google/Protobuf/Internal/SourceCodeInfo_Location.php
index b33013b8..19ed2bc2 100644
--- a/php/src/Google/Protobuf/Internal/SourceCodeInfo_Location.php
+++ b/php/src/Google/Protobuf/Internal/SourceCodeInfo_Location.php
@@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
-
use Google\Protobuf\Internal\GPBUtil;
/**
@@ -170,7 +169,7 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message
* @param int[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setPath(&$var)
+ public function setPath($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32);
$this->path = $arr;
@@ -210,7 +209,7 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message
* @param int[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setSpan(&$var)
+ public function setSpan($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32);
$this->span = $arr;
@@ -368,7 +367,7 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message
* @param string[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setLeadingDetachedComments(&$var)
+ public function setLeadingDetachedComments($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING);
$this->leading_detached_comments = $arr;
diff --git a/php/src/Google/Protobuf/Internal/UninterpretedOption.php b/php/src/Google/Protobuf/Internal/UninterpretedOption.php
index a4fab343..4d342eb3 100644
--- a/php/src/Google/Protobuf/Internal/UninterpretedOption.php
+++ b/php/src/Google/Protobuf/Internal/UninterpretedOption.php
@@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
-
use Google\Protobuf\Internal\GPBUtil;
/**
@@ -81,7 +80,7 @@ class UninterpretedOption extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\UninterpretedOption_NamePart[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
- public function setName(&$var)
+ public function setName($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption_NamePart::class);
$this->name = $arr;
diff --git a/php/src/Google/Protobuf/Internal/UninterpretedOption_NamePart.php b/php/src/Google/Protobuf/Internal/UninterpretedOption_NamePart.php
index 69a96d45..c9a6fc3c 100644
--- a/php/src/Google/Protobuf/Internal/UninterpretedOption_NamePart.php
+++ b/php/src/Google/Protobuf/Internal/UninterpretedOption_NamePart.php
@@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
-
use Google\Protobuf\Internal\GPBUtil;
/**
diff --git a/php/tests/array_test.php b/php/tests/array_test.php
index 271389ba..e57f0a7e 100644
--- a/php/tests/array_test.php
+++ b/php/tests/array_test.php
@@ -521,21 +521,23 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase
# Test memory leak
#########################################################
- public function testCycleLeak()
- {
- $arr = new RepeatedField(GPBType::MESSAGE, TestMessage::class);
- $arr[] = new TestMessage;
- $arr[0]->SetRepeatedRecursive($arr);
-
- // Clean up memory before test.
- gc_collect_cycles();
- $start = memory_get_usage();
- unset($arr);
-
- // Explicitly trigger garbage collection.
- gc_collect_cycles();
-
- $end = memory_get_usage();
- $this->assertLessThan($start, $end);
- }
+ // COMMENTED OUT BY @bshaffer
+ // @see https://github.com/google/protobuf/pull/3344#issuecomment-315162761
+ // public function testCycleLeak()
+ // {
+ // $arr = new RepeatedField(GPBType::MESSAGE, TestMessage::class);
+ // $arr[] = new TestMessage;
+ // $arr[0]->SetRepeatedRecursive($arr);
+
+ // // Clean up memory before test.
+ // gc_collect_cycles();
+ // $start = memory_get_usage();
+ // unset($arr);
+
+ // // Explicitly trigger garbage collection.
+ // gc_collect_cycles();
+
+ // $end = memory_get_usage();
+ // $this->assertLessThan($start, $end);
+ // }
}
diff --git a/php/tests/encode_decode_test.php b/php/tests/encode_decode_test.php
index e2912ad4..b43dffb4 100644
--- a/php/tests/encode_decode_test.php
+++ b/php/tests/encode_decode_test.php
@@ -9,437 +9,445 @@ use Foo\TestEnum;
use Foo\TestMessage;
use Foo\TestMessage_Sub;
use Foo\TestPackedMessage;
+use Foo\TestRandomFieldOrder;
use Foo\TestUnpackedMessage;
class EncodeDecodeTest extends TestBase
{
-# public function testEncode()
-# {
-# $from = new TestMessage();
-# $this->expectEmptyFields($from);
-# $this->setFields($from);
-# $this->expectFields($from);
-#
-# $data = $from->serializeToString();
-# $this->assertSame(bin2hex(TestUtil::getGoldenTestMessage()),
-# bin2hex($data));
-# }
-#
-# public function testDecode()
-# {
-# $to = new TestMessage();
-# $to->mergeFromString(TestUtil::getGoldenTestMessage());
-# $this->expectFields($to);
-# }
-#
-# public function testEncodeDecode()
-# {
-# $from = new TestMessage();
-# $this->expectEmptyFields($from);
-# $this->setFields($from);
-# $this->expectFields($from);
-#
-# $data = $from->serializeToString();
-#
-# $to = new TestMessage();
-# $to->mergeFromString($data);
-# $this->expectFields($to);
-# }
-#
-# public function testEncodeDecodeEmpty()
-# {
-# $from = new TestMessage();
-# $this->expectEmptyFields($from);
-#
-# $data = $from->serializeToString();
-#
-# $to = new TestMessage();
-# $to->mergeFromString($data);
-# $this->expectEmptyFields($to);
-# }
+ public function testEncode()
+ {
+ $from = new TestMessage();
+ $this->expectEmptyFields($from);
+ $this->setFields($from);
+ $this->expectFields($from);
+
+ $data = $from->serializeToString();
+ $this->assertSame(bin2hex(TestUtil::getGoldenTestMessage()),
+ bin2hex($data));
+ }
+
+ public function testDecode()
+ {
+ $to = new TestMessage();
+ $to->mergeFromString(TestUtil::getGoldenTestMessage());
+ $this->expectFields($to);
+ }
+
+ public function testEncodeDecode()
+ {
+ $from = new TestMessage();
+ $this->expectEmptyFields($from);
+ $this->setFields($from);
+ $this->expectFields($from);
+
+ $data = $from->serializeToString();
+
+ $to = new TestMessage();
+ $to->mergeFromString($data);
+ $this->expectFields($to);
+ }
+
+ public function testEncodeDecodeEmpty()
+ {
+ $from = new TestMessage();
+ $this->expectEmptyFields($from);
+
+ $data = $from->serializeToString();
+
+ $to = new TestMessage();
+ $to->mergeFromString($data);
+ $this->expectEmptyFields($to);
+ }
public function testEncodeDecodeOneof()
{
$m = new TestMessage();
-# $m->setOneofInt32(1);
-# $data = $m->serializeToString();
-# $n = new TestMessage();
-# $n->mergeFromString($data);
-# $this->assertSame(1, $n->getOneofInt32());
-#
-# $m->setOneofFloat(2.0);
-# $data = $m->serializeToString();
-# $n = new TestMessage();
-# $n->mergeFromString($data);
-# $this->assertSame(2.0, $n->getOneofFloat());
-#
-# $m->setOneofString('abc');
-# $data = $m->serializeToString();
-# $n = new TestMessage();
-# $n->mergeFromString($data);
-# $this->assertSame('abc', $n->getOneofString());
-#
-# $sub_m = new TestMessage_Sub();
-# $sub_m->setA(1);
-# $m->setOneofMessage($sub_m);
-# $data = $m->serializeToString();
-# $n = new TestMessage();
-# $n->mergeFromString($data);
-# $this->assertSame(1, $n->getOneofMessage()->getA());
+ $m->setOneofInt32(1);
+ $data = $m->serializeToString();
+ $n = new TestMessage();
+ $n->mergeFromString($data);
+ $this->assertSame(1, $n->getOneofInt32());
+
+ $m->setOneofFloat(2.0);
+ $data = $m->serializeToString();
+ $n = new TestMessage();
+ $n->mergeFromString($data);
+ $this->assertSame(2.0, $n->getOneofFloat());
+
+ $m->setOneofString('abc');
+ $data = $m->serializeToString();
+ $n = new TestMessage();
+ $n->mergeFromString($data);
+ $this->assertSame('abc', $n->getOneofString());
+
+ $sub_m = new TestMessage_Sub();
+ $sub_m->setA(1);
+ $m->setOneofMessage($sub_m);
+ $data = $m->serializeToString();
+ $n = new TestMessage();
+ $n->mergeFromString($data);
+ $this->assertSame(1, $n->getOneofMessage()->getA());
// Encode default value
-# $m->setOneofEnum(TestEnum::ZERO);
-# $data = $m->serializeToString();
-# $n = new TestMessage();
-# $n->mergeFromString($data);
-# $this->assertSame("oneof_enum", $n->getMyOneof());
-# $this->assertSame(TestEnum::ZERO, $n->getOneofEnum());
+ $m->setOneofEnum(TestEnum::ZERO);
+ $data = $m->serializeToString();
+ $n = new TestMessage();
+ $n->mergeFromString($data);
+ $this->assertSame("oneof_enum", $n->getMyOneof());
+ $this->assertSame(TestEnum::ZERO, $n->getOneofEnum());
$m->setOneofString("");
$data = $m->serializeToString();
$n = new TestMessage();
$n->mergeFromString($data);
$this->assertSame("oneof_string", $n->getMyOneof());
- $this->assertSame("", $n->getOneofString());
-
-# $sub_m = new TestMessage_Sub();
-# $m->setOneofMessage($sub_m);
-# $data = $m->serializeToString();
-# $n = new TestMessage();
-# $n->mergeFromString($data);
-# $this->assertSame("oneof_message", $n->getMyOneof());
-# $this->assertFalse(is_null($n->getOneofMessage()));
-
- }
-
-# public function testPackedEncode()
-# {
-# $from = new TestPackedMessage();
-# TestUtil::setTestPackedMessage($from);
-# $this->assertSame(TestUtil::getGoldenTestPackedMessage(),
-# $from->serializeToString());
-# }
-#
-# public function testPackedDecodePacked()
-# {
-# $to = new TestPackedMessage();
-# $to->mergeFromString(TestUtil::getGoldenTestPackedMessage());
-# TestUtil::assertTestPackedMessage($to);
-# }
-#
-# public function testPackedDecodeUnpacked()
-# {
-# $to = new TestPackedMessage();
-# $to->mergeFromString(TestUtil::getGoldenTestUnpackedMessage());
-# TestUtil::assertTestPackedMessage($to);
-# }
-#
-# public function testUnpackedEncode()
-# {
-# $from = new TestUnpackedMessage();
-# TestUtil::setTestPackedMessage($from);
-# $this->assertSame(TestUtil::getGoldenTestUnpackedMessage(),
-# $from->serializeToString());
-# }
-#
-# public function testUnpackedDecodePacked()
-# {
-# $to = new TestUnpackedMessage();
-# $to->mergeFromString(TestUtil::getGoldenTestPackedMessage());
-# TestUtil::assertTestPackedMessage($to);
-# }
-#
-# public function testUnpackedDecodeUnpacked()
-# {
-# $to = new TestUnpackedMessage();
-# $to->mergeFromString(TestUtil::getGoldenTestUnpackedMessage());
-# TestUtil::assertTestPackedMessage($to);
-# }
-#
-# public function testDecodeInt64()
-# {
-# // Read 64 testing
-# $testVals = array(
-# '10' => '100a',
-# '100' => '1064',
-# '800' => '10a006',
-# '6400' => '108032',
-# '70400' => '1080a604',
-# '774400' => '1080a22f',
-# '9292800' => '108098b704',
-# '74342400' => '1080c0b923',
-# '743424000' => '108080bfe202',
-# '8177664000' => '108080b5bb1e',
-# '65421312000' => '108080a8dbf301',
-# '785055744000' => '108080e0c7ec16',
-# '9420668928000' => '10808080dd969202',
-# '103627358208000' => '10808080fff9c717',
-# '1139900940288000' => '10808080f5bd978302',
-# '13678811283456000' => '10808080fce699a618',
-# '109430490267648000' => '10808080e0b7ceb1c201',
-# '984874412408832000' => '10808080e0f5c1bed50d',
-# );
-#
-# $msg = new TestMessage();
-# foreach ($testVals as $original => $encoded) {
-# $msg->setOptionalInt64($original);
-# $data = $msg->serializeToString();
-# $this->assertSame($encoded, bin2hex($data));
-# $msg->setOptionalInt64(0);
-# $msg->mergeFromString($data);
-# $this->assertEquals($original, $msg->getOptionalInt64());
-# }
-# }
-#
-# public function testDecodeToExistingMessage()
-# {
-# $m1 = new TestMessage();
-# $this->setFields($m1);
-# $this->expectFields($m1);
-#
-# $m2 = new TestMessage();
-# $this->setFields2($m2);
-# $data = $m2->serializeToString();
-#
-# $m1->mergeFromString($data);
-# $this->expectFieldsMerged($m1);
-# }
-#
-# public function testDecodeFieldNonExist()
-# {
-# $data = hex2bin('c80501');
-# $m = new TestMessage();
-# $m->mergeFromString($data);
-# }
-#
-# public function testEncodeNegativeInt32()
-# {
-# $m = new TestMessage();
-# $m->setOptionalInt32(-1);
-# $data = $m->serializeToString();
-# $this->assertSame("08ffffffffffffffffff01", bin2hex($data));
-# }
-#
-# public function testDecodeNegativeInt32()
-# {
-# $m = new TestMessage();
-# $this->assertEquals(0, $m->getOptionalInt32());
-# $m->mergeFromString(hex2bin("08ffffffffffffffffff01"));
-# $this->assertEquals(-1, $m->getOptionalInt32());
-#
-# $m = new TestMessage();
-# $this->assertEquals(0, $m->getOptionalInt32());
-# $m->mergeFromString(hex2bin("08ffffffff0f"));
-# $this->assertEquals(-1, $m->getOptionalInt32());
-# }
-#
-# /**
-# * @expectedException Exception
-# */
-# public function testDecodeInvalidInt32()
-# {
-# $m = new TestMessage();
-# $m->mergeFromString(hex2bin('08'));
-# }
-#
-# /**
-# * @expectedException Exception
-# */
-# public function testDecodeInvalidSubMessage()
-# {
-# $m = new TestMessage();
-# $m->mergeFromString(hex2bin('9A010108'));
-# }
-#
-# /**
-# * @expectedException Exception
-# */
-# public function testDecodeInvalidInt64()
-# {
-# $m = new TestMessage();
-# $m->mergeFromString(hex2bin('10'));
-# }
-#
-# /**
-# * @expectedException Exception
-# */
-# public function testDecodeInvalidUInt32()
-# {
-# $m = new TestMessage();
-# $m->mergeFromString(hex2bin('18'));
-# }
-#
-# /**
-# * @expectedException Exception
-# */
-# public function testDecodeInvalidUInt64()
-# {
-# $m = new TestMessage();
-# $m->mergeFromString(hex2bin('20'));
-# }
-#
-# /**
-# * @expectedException Exception
-# */
-# public function testDecodeInvalidSInt32()
-# {
-# $m = new TestMessage();
-# $m->mergeFromString(hex2bin('28'));
-# }
-#
-# /**
-# * @expectedException Exception
-# */
-# public function testDecodeInvalidSInt64()
-# {
-# $m = new TestMessage();
-# $m->mergeFromString(hex2bin('30'));
-# }
-#
-# /**
-# * @expectedException Exception
-# */
-# public function testDecodeInvalidFixed32()
-# {
-# $m = new TestMessage();
-# $m->mergeFromString(hex2bin('3D'));
-# }
-#
-# /**
-# * @expectedException Exception
-# */
-# public function testDecodeInvalidFixed64()
-# {
-# $m = new TestMessage();
-# $m->mergeFromString(hex2bin('41'));
-# }
-#
-# /**
-# * @expectedException Exception
-# */
-# public function testDecodeInvalidSFixed32()
-# {
-# $m = new TestMessage();
-# $m->mergeFromString(hex2bin('4D'));
-# }
-#
-# /**
-# * @expectedException Exception
-# */
-# public function testDecodeInvalidSFixed64()
-# {
-# $m = new TestMessage();
-# $m->mergeFromString(hex2bin('51'));
-# }
-#
-# /**
-# * @expectedException Exception
-# */
-# public function testDecodeInvalidFloat()
-# {
-# $m = new TestMessage();
-# $m->mergeFromString(hex2bin('5D'));
-# }
-#
-# /**
-# * @expectedException Exception
-# */
-# public function testDecodeInvalidDouble()
-# {
-# $m = new TestMessage();
-# $m->mergeFromString(hex2bin('61'));
-# }
-#
-# /**
-# * @expectedException Exception
-# */
-# public function testDecodeInvalidBool()
-# {
-# $m = new TestMessage();
-# $m->mergeFromString(hex2bin('68'));
-# }
-#
-# /**
-# * @expectedException Exception
-# */
-# public function testDecodeInvalidStringLengthMiss()
-# {
-# $m = new TestMessage();
-# $m->mergeFromString(hex2bin('72'));
-# }
-#
-# /**
-# * @expectedException Exception
-# */
-# public function testDecodeInvalidStringDataMiss()
-# {
-# $m = new TestMessage();
-# $m->mergeFromString(hex2bin('7201'));
-# }
-#
-# /**
-# * @expectedException Exception
-# */
-# public function testDecodeInvalidBytesLengthMiss()
-# {
-# $m = new TestMessage();
-# $m->mergeFromString(hex2bin('7A'));
-# }
-#
-# /**
-# * @expectedException Exception
-# */
-# public function testDecodeInvalidBytesDataMiss()
-# {
-# $m = new TestMessage();
-# $m->mergeFromString(hex2bin('7A01'));
-# }
-#
-# /**
-# * @expectedException Exception
-# */
-# public function testDecodeInvalidEnum()
-# {
-# $m = new TestMessage();
-# $m->mergeFromString(hex2bin('8001'));
-# }
-#
-# /**
-# * @expectedException Exception
-# */
-# public function testDecodeInvalidMessageLengthMiss()
-# {
-# $m = new TestMessage();
-# $m->mergeFromString(hex2bin('8A01'));
-# }
-#
-# /**
-# * @expectedException Exception
-# */
-# public function testDecodeInvalidMessageDataMiss()
-# {
-# $m = new TestMessage();
-# $m->mergeFromString(hex2bin('8A0101'));
-# }
-#
-# /**
-# * @expectedException Exception
-# */
-# public function testDecodeInvalidPackedMessageLength()
-# {
-# $m = new TestPackedMessage();
-# $m->mergeFromString(hex2bin('D205'));
-# }
-#
-# public function testJsonEncode()
-# {
-# $from = new TestMessage();
-# $this->setFields($from);
-# $data = $from->serializeToJsonString();
-# $to = new TestMessage();
-# $to->mergeFromJsonString($data);
-# $this->expectFields($to);
-# }
+ $this->assertSame("", $n->getOneofString());
+
+ $sub_m = new TestMessage_Sub();
+ $m->setOneofMessage($sub_m);
+ $data = $m->serializeToString();
+ $n = new TestMessage();
+ $n->mergeFromString($data);
+ $this->assertSame("oneof_message", $n->getMyOneof());
+ $this->assertFalse(is_null($n->getOneofMessage()));
+
+ }
+
+ public function testPackedEncode()
+ {
+ $from = new TestPackedMessage();
+ TestUtil::setTestPackedMessage($from);
+ $this->assertSame(TestUtil::getGoldenTestPackedMessage(),
+ $from->serializeToString());
+ }
+
+ public function testPackedDecodePacked()
+ {
+ $to = new TestPackedMessage();
+ $to->mergeFromString(TestUtil::getGoldenTestPackedMessage());
+ TestUtil::assertTestPackedMessage($to);
+ }
+
+ public function testPackedDecodeUnpacked()
+ {
+ $to = new TestPackedMessage();
+ $to->mergeFromString(TestUtil::getGoldenTestUnpackedMessage());
+ TestUtil::assertTestPackedMessage($to);
+ }
+
+ public function testUnpackedEncode()
+ {
+ $from = new TestUnpackedMessage();
+ TestUtil::setTestPackedMessage($from);
+ $this->assertSame(TestUtil::getGoldenTestUnpackedMessage(),
+ $from->serializeToString());
+ }
+
+ public function testUnpackedDecodePacked()
+ {
+ $to = new TestUnpackedMessage();
+ $to->mergeFromString(TestUtil::getGoldenTestPackedMessage());
+ TestUtil::assertTestPackedMessage($to);
+ }
+
+ public function testUnpackedDecodeUnpacked()
+ {
+ $to = new TestUnpackedMessage();
+ $to->mergeFromString(TestUtil::getGoldenTestUnpackedMessage());
+ TestUtil::assertTestPackedMessage($to);
+ }
+
+ public function testDecodeInt64()
+ {
+ // Read 64 testing
+ $testVals = array(
+ '10' => '100a',
+ '100' => '1064',
+ '800' => '10a006',
+ '6400' => '108032',
+ '70400' => '1080a604',
+ '774400' => '1080a22f',
+ '9292800' => '108098b704',
+ '74342400' => '1080c0b923',
+ '743424000' => '108080bfe202',
+ '8177664000' => '108080b5bb1e',
+ '65421312000' => '108080a8dbf301',
+ '785055744000' => '108080e0c7ec16',
+ '9420668928000' => '10808080dd969202',
+ '103627358208000' => '10808080fff9c717',
+ '1139900940288000' => '10808080f5bd978302',
+ '13678811283456000' => '10808080fce699a618',
+ '109430490267648000' => '10808080e0b7ceb1c201',
+ '984874412408832000' => '10808080e0f5c1bed50d',
+ );
+
+ $msg = new TestMessage();
+ foreach ($testVals as $original => $encoded) {
+ $msg->setOptionalInt64($original);
+ $data = $msg->serializeToString();
+ $this->assertSame($encoded, bin2hex($data));
+ $msg->setOptionalInt64(0);
+ $msg->mergeFromString($data);
+ $this->assertEquals($original, $msg->getOptionalInt64());
+ }
+ }
+
+ public function testDecodeToExistingMessage()
+ {
+ $m1 = new TestMessage();
+ $this->setFields($m1);
+ $this->expectFields($m1);
+
+ $m2 = new TestMessage();
+ $this->setFields2($m2);
+ $data = $m2->serializeToString();
+
+ $m1->mergeFromString($data);
+ $this->expectFieldsMerged($m1);
+ }
+
+ public function testDecodeFieldNonExist()
+ {
+ $data = hex2bin('c80501');
+ $m = new TestMessage();
+ $m->mergeFromString($data);
+ }
+
+ public function testEncodeNegativeInt32()
+ {
+ $m = new TestMessage();
+ $m->setOptionalInt32(-1);
+ $data = $m->serializeToString();
+ $this->assertSame("08ffffffffffffffffff01", bin2hex($data));
+ }
+
+ public function testDecodeNegativeInt32()
+ {
+ $m = new TestMessage();
+ $this->assertEquals(0, $m->getOptionalInt32());
+ $m->mergeFromString(hex2bin("08ffffffffffffffffff01"));
+ $this->assertEquals(-1, $m->getOptionalInt32());
+
+ $m = new TestMessage();
+ $this->assertEquals(0, $m->getOptionalInt32());
+ $m->mergeFromString(hex2bin("08ffffffff0f"));
+ $this->assertEquals(-1, $m->getOptionalInt32());
+ }
+
+ public function testRandomFieldOrder()
+ {
+ $m = new TestRandomFieldOrder();
+ $data = $m->serializeToString();
+ $this->assertSame("", $data);
+ }
+
+ /**
+ * @expectedException Exception
+ */
+ public function testDecodeInvalidInt32()
+ {
+ $m = new TestMessage();
+ $m->mergeFromString(hex2bin('08'));
+ }
+
+ /**
+ * @expectedException Exception
+ */
+ public function testDecodeInvalidSubMessage()
+ {
+ $m = new TestMessage();
+ $m->mergeFromString(hex2bin('9A010108'));
+ }
+
+ /**
+ * @expectedException Exception
+ */
+ public function testDecodeInvalidInt64()
+ {
+ $m = new TestMessage();
+ $m->mergeFromString(hex2bin('10'));
+ }
+
+ /**
+ * @expectedException Exception
+ */
+ public function testDecodeInvalidUInt32()
+ {
+ $m = new TestMessage();
+ $m->mergeFromString(hex2bin('18'));
+ }
+
+ /**
+ * @expectedException Exception
+ */
+ public function testDecodeInvalidUInt64()
+ {
+ $m = new TestMessage();
+ $m->mergeFromString(hex2bin('20'));
+ }
+
+ /**
+ * @expectedException Exception
+ */
+ public function testDecodeInvalidSInt32()
+ {
+ $m = new TestMessage();
+ $m->mergeFromString(hex2bin('28'));
+ }
+
+ /**
+ * @expectedException Exception
+ */
+ public function testDecodeInvalidSInt64()
+ {
+ $m = new TestMessage();
+ $m->mergeFromString(hex2bin('30'));
+ }
+
+ /**
+ * @expectedException Exception
+ */
+ public function testDecodeInvalidFixed32()
+ {
+ $m = new TestMessage();
+ $m->mergeFromString(hex2bin('3D'));
+ }
+
+ /**
+ * @expectedException Exception
+ */
+ public function testDecodeInvalidFixed64()
+ {
+ $m = new TestMessage();
+ $m->mergeFromString(hex2bin('41'));
+ }
+
+ /**
+ * @expectedException Exception
+ */
+ public function testDecodeInvalidSFixed32()
+ {
+ $m = new TestMessage();
+ $m->mergeFromString(hex2bin('4D'));
+ }
+
+ /**
+ * @expectedException Exception
+ */
+ public function testDecodeInvalidSFixed64()
+ {
+ $m = new TestMessage();
+ $m->mergeFromString(hex2bin('51'));
+ }
+
+ /**
+ * @expectedException Exception
+ */
+ public function testDecodeInvalidFloat()
+ {
+ $m = new TestMessage();
+ $m->mergeFromString(hex2bin('5D'));
+ }
+
+ /**
+ * @expectedException Exception
+ */
+ public function testDecodeInvalidDouble()
+ {
+ $m = new TestMessage();
+ $m->mergeFromString(hex2bin('61'));
+ }
+
+ /**
+ * @expectedException Exception
+ */
+ public function testDecodeInvalidBool()
+ {
+ $m = new TestMessage();
+ $m->mergeFromString(hex2bin('68'));
+ }
+
+ /**
+ * @expectedException Exception
+ */
+ public function testDecodeInvalidStringLengthMiss()
+ {
+ $m = new TestMessage();
+ $m->mergeFromString(hex2bin('72'));
+ }
+
+ /**
+ * @expectedException Exception
+ */
+ public function testDecodeInvalidStringDataMiss()
+ {
+ $m = new TestMessage();
+ $m->mergeFromString(hex2bin('7201'));
+ }
+
+ /**
+ * @expectedException Exception
+ */
+ public function testDecodeInvalidBytesLengthMiss()
+ {
+ $m = new TestMessage();
+ $m->mergeFromString(hex2bin('7A'));
+ }
+
+ /**
+ * @expectedException Exception
+ */
+ public function testDecodeInvalidBytesDataMiss()
+ {
+ $m = new TestMessage();
+ $m->mergeFromString(hex2bin('7A01'));
+ }
+
+ /**
+ * @expectedException Exception
+ */
+ public function testDecodeInvalidEnum()
+ {
+ $m = new TestMessage();
+ $m->mergeFromString(hex2bin('8001'));
+ }
+
+ /**
+ * @expectedException Exception
+ */
+ public function testDecodeInvalidMessageLengthMiss()
+ {
+ $m = new TestMessage();
+ $m->mergeFromString(hex2bin('8A01'));
+ }
+
+ /**
+ * @expectedException Exception
+ */
+ public function testDecodeInvalidMessageDataMiss()
+ {
+ $m = new TestMessage();
+ $m->mergeFromString(hex2bin('8A0101'));
+ }
+
+ /**
+ * @expectedException Exception
+ */
+ public function testDecodeInvalidPackedMessageLength()
+ {
+ $m = new TestPackedMessage();
+ $m->mergeFromString(hex2bin('D205'));
+ }
+
+ public function testJsonEncode()
+ {
+ $from = new TestMessage();
+ $this->setFields($from);
+ $data = $from->serializeToJsonString();
+ $to = new TestMessage();
+ $to->mergeFromJsonString($data);
+ $this->expectFields($to);
+ }
}
diff --git a/php/tests/generated_service_test.php b/php/tests/generated_service_test.php
new file mode 100644
index 00000000..5407db9a
--- /dev/null
+++ b/php/tests/generated_service_test.php
@@ -0,0 +1,110 @@
+<?php
+
+require_once('test_base.php');
+require_once('test_util.php');
+
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\MapField;
+use Google\Protobuf\Internal\GPBType;
+use Foo\Greeter;
+use Foo\HelloRequest;
+use Foo\HelloReply;
+
+class GeneratedServiceTest extends TestBase
+{
+ /**
+ * @var \ReflectionClass
+ */
+ private $serviceClass;
+
+ /**
+ * @var \ReflectionClass
+ */
+ private $namespacedServiceClass;
+
+ /**
+ * @var array
+ */
+ private $methodNames = [
+ 'sayHello',
+ 'sayHelloAgain'
+ ];
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->serviceClass = new ReflectionClass('Foo\GreeterInterface');
+
+ $this->namespacedServiceClass = new ReflectionClass('Bar\OtherGreeterInterface');
+ }
+
+ public function testIsInterface()
+ {
+ $this->assertTrue($this->serviceClass->isInterface());
+ }
+
+ public function testPhpDocForClass()
+ {
+ $this->assertContains('foo.Greeter', $this->serviceClass->getDocComment());
+ }
+
+ public function testPhpDocForNamespacedClass()
+ {
+ $this->assertContains('foo.OtherGreeter', $this->namespacedServiceClass->getDocComment());
+ }
+
+ public function testServiceMethodsAreGenerated()
+ {
+ $this->assertCount(count($this->methodNames), $this->serviceClass->getMethods());
+ foreach ($this->methodNames as $methodName) {
+ $this->assertTrue($this->serviceClass->hasMethod($methodName));
+ }
+ }
+
+ public function testPhpDocForServiceMethod()
+ {
+ foreach ($this->methodNames as $methodName) {
+ $docComment = $this->serviceClass->getMethod($methodName)->getDocComment();
+ $this->assertContains($methodName, $docComment);
+ $this->assertContains('@param \Foo\HelloRequest $request', $docComment);
+ $this->assertContains('@return \Foo\HelloReply', $docComment);
+ }
+ }
+
+ public function testPhpDocForServiceMethodInNamespacedClass()
+ {
+ foreach ($this->methodNames as $methodName) {
+ $docComment = $this->namespacedServiceClass->getMethod($methodName)->getDocComment();
+ $this->assertContains($methodName, $docComment);
+ $this->assertContains('@param \Foo\HelloRequest $request', $docComment);
+ $this->assertContains('@return \Foo\HelloReply', $docComment);
+ }
+ }
+
+ public function testParamForServiceMethod()
+ {
+ foreach ($this->methodNames as $methodName) {
+ $method = $this->serviceClass->getMethod($methodName);
+ $this->assertCount(1, $method->getParameters());
+ $param = $method->getParameters()[0];
+ $this->assertFalse($param->isOptional());
+ $this->assertSame('request', $param->getName());
+ // ReflectionParameter::getType only exists in PHP 7+, so get the type from __toString
+ $this->assertContains('Foo\HelloRequest $request', (string) $param);
+ }
+ }
+
+ public function testParamForServiceMethodInNamespacedClass()
+ {
+ foreach ($this->methodNames as $methodName) {
+ $method = $this->serviceClass->getMethod($methodName);
+ $this->assertCount(1, $method->getParameters());
+ $param = $method->getParameters()[0];
+ $this->assertFalse($param->isOptional());
+ $this->assertSame('request', $param->getName());
+ // ReflectionParameter::getType only exists in PHP 7+, so get the type from __toString
+ $this->assertContains('Foo\HelloRequest $request', (string) $param);
+ }
+ }
+}
diff --git a/php/tests/map_field_test.php b/php/tests/map_field_test.php
index c5d21264..120b1bde 100644
--- a/php/tests/map_field_test.php
+++ b/php/tests/map_field_test.php
@@ -56,6 +56,23 @@ class MapFieldTest extends PHPUnit_Framework_TestCase {
unset($arr['3.1']);
unset($arr[MAX_INT32_STRING]);
$this->assertEquals(0, count($arr));
+
+ // Test foreach.
+ $arr = new MapField(GPBType::INT32, GPBType::INT32);
+ for ($i = 0; $i < 3; $i++) {
+ $arr[$i] = $i;
+ }
+ $i = 0;
+ $arr_test = [];
+ foreach ($arr as $key => $val) {
+ $this->assertSame($key, $val);
+ $arr_test[] = $key;
+ $i++;
+ }
+ $this->assertTrue(isset($arr_test[0]));
+ $this->assertTrue(isset($arr_test[1]));
+ $this->assertTrue(isset($arr_test[2]));
+ $this->assertSame(3, $i);
}
#########################################################
@@ -366,6 +383,23 @@ class MapFieldTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(1, count($arr));
unset($arr[True]);
$this->assertEquals(0, count($arr));
+
+ // Test foreach.
+ $arr = new MapField(GPBType::STRING, GPBType::STRING);
+ for ($i = 0; $i < 3; $i++) {
+ $arr[$i] = $i;
+ }
+ $i = 0;
+ $arr_test = [];
+ foreach ($arr as $key => $val) {
+ $this->assertSame($key, $val);
+ $arr_test[] = $key;
+ $i++;
+ }
+ $this->assertTrue(isset($arr_test['0']));
+ $this->assertTrue(isset($arr_test['1']));
+ $this->assertTrue(isset($arr_test['2']));
+ $this->assertSame(3, $i);
}
#########################################################
diff --git a/php/tests/memory_leak_test.php b/php/tests/memory_leak_test.php
index 6572fdd0..faa1833d 100644
--- a/php/tests/memory_leak_test.php
+++ b/php/tests/memory_leak_test.php
@@ -20,6 +20,7 @@ require_once('generated/Foo/TestMessage_NestedEnum.php');
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/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 dada8b48..d81f66f5 100644
--- a/php/tests/proto/test.proto
+++ b/php/tests/proto/test.proto
@@ -181,3 +181,9 @@ message TestIncludeNamespaceMessage {
TestNamespace namespace_message = 1;
TestEmptyNamespace empty_namespace_message = 2;
}
+
+// This will cause upb fields not ordered by the order in the generated code.
+message TestRandomFieldOrder {
+ int64 tag13 = 150;
+ string tag14 = 160;
+}
diff --git a/php/tests/proto/test_service.proto b/php/tests/proto/test_service.proto
new file mode 100644
index 00000000..a03dbc46
--- /dev/null
+++ b/php/tests/proto/test_service.proto
@@ -0,0 +1,18 @@
+syntax = "proto3";
+
+package foo;
+
+option php_generic_services = true;
+
+service Greeter {
+ rpc SayHello (HelloRequest) returns (HelloReply) {}
+ rpc SayHelloAgain (HelloRequest) returns (HelloReply) {}
+}
+
+message HelloRequest {
+ string name = 1;
+}
+
+message HelloReply {
+ string message = 1;
+}
diff --git a/php/tests/proto/test_service_namespace.proto b/php/tests/proto/test_service_namespace.proto
new file mode 100644
index 00000000..719aa484
--- /dev/null
+++ b/php/tests/proto/test_service_namespace.proto
@@ -0,0 +1,13 @@
+syntax = "proto3";
+
+import "proto/test_service.proto";
+
+package foo;
+
+option php_generic_services = true;
+option php_namespace = "Bar";
+
+service OtherGreeter {
+ rpc SayHello (HelloRequest) returns (HelloReply) {}
+ rpc SayHelloAgain (HelloRequest) returns (HelloReply) {}
+}
diff --git a/php/tests/test.sh b/php/tests/test.sh
index 6c6edd56..b640c143 100755
--- a/php/tests/test.sh
+++ b/php/tests/test.sh
@@ -8,7 +8,7 @@ set -e
phpize && ./configure CFLAGS='-g -O0' && make
popd
-tests=( array_test.php encode_decode_test.php generated_class_test.php generated_phpdoc_test.php map_field_test.php well_known_test.php )
+tests=( array_test.php encode_decode_test.php generated_class_test.php generated_phpdoc_test.php map_field_test.php well_known_test.php generated_service_test.php )
for t in "${tests[@]}"
do