aboutsummaryrefslogtreecommitdiff
path: root/php/ext/google/protobuf/message.c
diff options
context:
space:
mode:
authorPaul Yang <TeBoring@users.noreply.github.com>2016-12-08 11:16:49 -0800
committerGitHub <noreply@github.com>2016-12-08 11:16:49 -0800
commit46ae90dc5e145b12fffa7e053a908a9f3e066286 (patch)
treee15e50f9a986bd64cd4413b135382a305701437f /php/ext/google/protobuf/message.c
parent631f4618a7b84cdc91949229a11a8abe5dfc4a34 (diff)
downloadprotobuf-46ae90dc5e145b12fffa7e053a908a9f3e066286.tar.gz
protobuf-46ae90dc5e145b12fffa7e053a908a9f3e066286.tar.bz2
protobuf-46ae90dc5e145b12fffa7e053a908a9f3e066286.zip
Make php generated code conform to PSR-4. (#2435)
1. Generate single file for each message. 2. Lazily initiate metadata.
Diffstat (limited to 'php/ext/google/protobuf/message.c')
-rw-r--r--php/ext/google/protobuf/message.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/php/ext/google/protobuf/message.c b/php/ext/google/protobuf/message.c
index d8fbbe11..16e397f5 100644
--- a/php/ext/google/protobuf/message.c
+++ b/php/ext/google/protobuf/message.c
@@ -41,6 +41,7 @@ static zend_function_entry message_methods[] = {
PHP_ME(Message, decode, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Message, readOneof, NULL, ZEND_ACC_PROTECTED)
PHP_ME(Message, writeOneof, NULL, ZEND_ACC_PROTECTED)
+ PHP_ME(Message, __construct, NULL, ZEND_ACC_PROTECTED)
{NULL, NULL, NULL}
};
@@ -210,6 +211,17 @@ void build_class_from_descriptor(zval* php_descriptor TSRMLS_DC) {
// PHP Methods
// -----------------------------------------------------------------------------
+// At the first time the message is created, the class entry hasn't been
+// modified. As a result, the first created instance will be a normal zend
+// object. Here, we manually modify it to our message in such a case.
+PHP_METHOD(Message, __construct) {
+ if (Z_OBJVAL_P(getThis()).handlers != message_handlers) {
+ zend_class_entry* ce = Z_OBJCE_P(getThis());
+ zval_dtor(getThis());
+ Z_OBJVAL_P(getThis()) = message_create(ce TSRMLS_CC);
+ }
+}
+
PHP_METHOD(Message, readOneof) {
long index;