瀏覽代碼

Fix well known type class not inheriting Message (#5095)

* Fix well known type class not inheriting Message

Previously, well known types only implement Message interface but not inhert it.
Fix the problem by calling zend_do_inheritance

* Add back commented tests
Paul Yang 7 年之前
父節點
當前提交
d05926861b
共有 2 個文件被更改,包括 4 次插入2 次删除
  1. 3 2
      php/ext/google/protobuf/protobuf.h
  2. 1 0
      php/tests/well_known_test.php

+ 3 - 2
php/ext/google/protobuf/protobuf.h

@@ -138,7 +138,8 @@
     INIT_CLASS_ENTRY_EX(class_type, CLASSNAME, strlen(CLASSNAME),            \
     INIT_CLASS_ENTRY_EX(class_type, CLASSNAME, strlen(CLASSNAME),            \
                         LOWWERNAME##_methods);                               \
                         LOWWERNAME##_methods);                               \
     LOWWERNAME##_type = zend_register_internal_class(&class_type TSRMLS_CC); \
     LOWWERNAME##_type = zend_register_internal_class(&class_type TSRMLS_CC); \
-    LOWWERNAME##_type->create_object = message_create;
+    LOWWERNAME##_type->create_object = message_create;                       \
+    zend_do_inheritance(LOWWERNAME##_type, message_type TSRMLS_CC);
 #define PHP_PROTO_INIT_SUBMSGCLASS_END \
 #define PHP_PROTO_INIT_SUBMSGCLASS_END \
   }
   }
 
 
@@ -404,7 +405,7 @@ static inline int php_proto_zend_hash_get_current_data_ex(HashTable* ht,
     INIT_CLASS_ENTRY_EX(class_type, CLASSNAME, strlen(CLASSNAME),            \
     INIT_CLASS_ENTRY_EX(class_type, CLASSNAME, strlen(CLASSNAME),            \
                         LOWWERNAME##_methods);                               \
                         LOWWERNAME##_methods);                               \
     LOWWERNAME##_type = zend_register_internal_class(&class_type TSRMLS_CC); \
     LOWWERNAME##_type = zend_register_internal_class(&class_type TSRMLS_CC); \
-    LOWWERNAME##_type->create_object = message_create;
+    zend_do_inheritance(LOWWERNAME##_type, message_type TSRMLS_CC);
 #define PHP_PROTO_INIT_SUBMSGCLASS_END \
 #define PHP_PROTO_INIT_SUBMSGCLASS_END \
   }
   }
 
 

+ 1 - 0
php/tests/well_known_test.php

@@ -42,6 +42,7 @@ class WellKnownTest extends TestBase {
     public function testEmpty()
     public function testEmpty()
     {
     {
         $msg = new GPBEmpty();
         $msg = new GPBEmpty();
+        $this->assertTrue($msg instanceof \Google\Protobuf\Internal\Message);
     }
     }
 
 
     public function testImportDescriptorProto()
     public function testImportDescriptorProto()