From: Stanislav Malyshev Date: Wed, 23 Feb 2005 11:15:51 +0000 (+0000) Subject: Custom object serializer infrastructure X-Git-Tag: RELEASE_0_3~235 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5b98a092195a7977fa3f4ab0d6d8918654d50ff9;p=php Custom object serializer infrastructure # The detailed announce on the list will follow --- diff --git a/Zend/zend.h b/Zend/zend.h index f8a059ad85..0583c09cb5 100644 --- a/Zend/zend.h +++ b/Zend/zend.h @@ -303,6 +303,12 @@ union _zend_function; #include "zend_iterators.h" +struct _zend_serialize_data; +struct _zend_unserialize_data; + +typedef struct _zend_serialize_data zend_serialize_data; +typedef struct _zend_unserialize_data zend_unserialize_data; + struct _zend_class_entry { char type; char *name; @@ -333,6 +339,10 @@ struct _zend_class_entry { zend_object_iterator *(*get_iterator)(zend_class_entry *ce, zval *object TSRMLS_DC); int (*interface_gets_implemented)(zend_class_entry *iface, zend_class_entry *class_type TSRMLS_DC); /* a class implements this interface */ + /* serializer callbacks */ + int (*serialize)(zval *object, unsigned char **buffer, zend_uint *buf_len, zend_serialize_data *data TSRMLS_DC); + int (*unserialize)(zval **object, const unsigned char *buf, zend_uint buf_len, zend_unserialize_data *data TSRMLS_DC); + zend_class_entry **interfaces; zend_uint num_interfaces; diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 32f2a3c26a..bf002ef947 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -1707,7 +1707,7 @@ static void do_inherit_parent_constructor(zend_class_entry *ce) /* You cannot change create_object */ ce->create_object = ce->parent->create_object; - + /* Inherit special functions if needed */ if (!ce->get_iterator) { ce->get_iterator = ce->parent->get_iterator; @@ -1727,12 +1727,19 @@ static void do_inherit_parent_constructor(zend_class_entry *ce) if (!ce->clone) { ce->clone = ce->parent->clone; } + if(!ce->serialize) { + ce->serialize = ce->parent->serialize; + } + if(!ce->unserialize) { + ce->unserialize = ce->parent->unserialize; + } if (!ce->destructor) { ce->destructor = ce->parent->destructor; } if (ce->constructor) { return; } + if (zend_hash_find(&ce->parent->function_table, ZEND_CONSTRUCTOR_FUNC_NAME, sizeof(ZEND_CONSTRUCTOR_FUNC_NAME), (void **)&function)==SUCCESS) { /* inherit parent's constructor */ zend_hash_update(&ce->function_table, ZEND_CONSTRUCTOR_FUNC_NAME, sizeof(ZEND_CONSTRUCTOR_FUNC_NAME), function, sizeof(zend_function), NULL); @@ -3839,6 +3846,8 @@ ZEND_API void zend_initialize_class_data(zend_class_entry *ce, zend_bool nullify ce->num_interfaces = 0; ce->interfaces = NULL; ce->module = NULL; + ce->serialize = NULL; + ce->unserialize = NULL; } }