Permalink
Browse files

MFH:

- Copy custom callback to the child class if any
- Prevent overwriting valid parent callbacks when implementing Serializable
- Export zend_user_(un)serialize to be available for custom callbacks
  • Loading branch information...
1 parent ce2f9bb commit cc9a8ee528a4d25240a1d3971a34431358c57119 @colder colder committed Aug 24, 2008
Showing with 22 additions and 7 deletions.
  1. +8 −0 Zend/zend_compile.c
  2. +11 −7 Zend/zend_interfaces.c
  3. +3 −0 Zend/zend_interfaces.h
View
@@ -2780,6 +2780,14 @@ ZEND_API void zend_do_inheritance(zend_class_entry *ce, zend_class_entry *parent
}
ce->parent = parent_ce;
+ /* Copy serialize/unserialize callbacks */
+ if (!ce->serialize) {
+ ce->serialize = parent_ce->serialize;
+ }
+ if (!ce->unserialize) {
+ ce->unserialize = parent_ce->unserialize;
+ }
+
/* Inherit interfaces */
zend_do_inherit_interfaces(ce, parent_ce TSRMLS_CC);
View
@@ -405,7 +405,7 @@ static int zend_implement_arrayaccess(zend_class_entry *interface, zend_class_en
/* }}}*/
/* {{{ zend_user_serialize */
-int zend_user_serialize(zval *object, unsigned char **buffer, zend_uint *buf_len, zend_serialize_data *data TSRMLS_DC)
+ZEND_API int zend_user_serialize(zval *object, unsigned char **buffer, zend_uint *buf_len, zend_serialize_data *data TSRMLS_DC)
{
zend_class_entry * ce = Z_OBJCE_P(object);
zval *retval;
@@ -442,7 +442,7 @@ int zend_user_serialize(zval *object, unsigned char **buffer, zend_uint *buf_len
/* }}} */
/* {{{ zend_user_unserialize */
-int zend_user_unserialize(zval **object, zend_class_entry *ce, const unsigned char *buf, zend_uint buf_len, zend_unserialize_data *data TSRMLS_DC)
+ZEND_API int zend_user_unserialize(zval **object, zend_class_entry *ce, const unsigned char *buf, zend_uint buf_len, zend_unserialize_data *data TSRMLS_DC)
{
zval * zdata;
@@ -466,13 +466,17 @@ int zend_user_unserialize(zval **object, zend_class_entry *ce, const unsigned ch
/* {{{ zend_implement_serializable */
static int zend_implement_serializable(zend_class_entry *interface, zend_class_entry *class_type TSRMLS_DC)
{
- if ((class_type->serialize && class_type->serialize != zend_user_serialize)
- || (class_type->unserialize && class_type->unserialize != zend_user_unserialize)
- ) {
+ if (class_type->parent
+ && (class_type->parent->serialize || class_type->parent->unserialize)
+ && !instanceof_function_ex(class_type->parent, zend_ce_serializable, 1 TSRMLS_CC)) {
return FAILURE;
}
- class_type->serialize = zend_user_serialize;
- class_type->unserialize = zend_user_unserialize;
+ if (!class_type->serialize) {
+ class_type->serialize = zend_user_serialize;
+ }
+ if (!class_type->unserialize) {
+ class_type->unserialize = zend_user_unserialize;
+ }
return SUCCESS;
}
/* }}}*/
View
@@ -61,6 +61,9 @@ ZEND_API zend_object_iterator *zend_user_it_get_new_iterator(zend_class_entry *c
ZEND_API void zend_register_interfaces(TSRMLS_D);
+ZEND_API int zend_user_serialize(zval *object, unsigned char **buffer, zend_uint *buf_len, zend_serialize_data *data TSRMLS_DC);
+ZEND_API int zend_user_unserialize(zval **object, zend_class_entry *ce, const unsigned char *buf, zend_uint buf_len, zend_unserialize_data *data TSRMLS_DC);
+
END_EXTERN_C()
#endif /* ZEND_INTERFACES_H */

0 comments on commit cc9a8ee

Please sign in to comment.