summaryrefslogtreecommitdiff
path: root/ext/standard/var.c
diff options
context:
space:
mode:
authorAndrey Hristov <andrey@php.net>2004-08-21 13:49:19 +0000
committerAndrey Hristov <andrey@php.net>2004-08-21 13:49:19 +0000
commitdd5538566e83eba0edde9a29eef1e80d5092f4b5 (patch)
tree7ba5ac7fbbd12ace2a4ca7dec51c8d61845b7929 /ext/standard/var.c
parente398e6b7d67c5342c5c9fe02b4a4ee8e043a9563 (diff)
downloadphp-git-dd5538566e83eba0edde9a29eef1e80d5092f4b5.tar.gz
fix for bug 26737 : private & protected member variables not serialized
when user defined __sleep() is declared. Additionally E_NOTICE is being thrown if __sleep() returns a non-existing member variable name
Diffstat (limited to 'ext/standard/var.c')
-rw-r--r--ext/standard/var.c36
1 files changed, 31 insertions, 5 deletions
diff --git a/ext/standard/var.c b/ext/standard/var.c
index 6d512fac1e..2b5154e08d 100644
--- a/ext/standard/var.c
+++ b/ext/standard/var.c
@@ -578,14 +578,40 @@ static void php_var_serialize_class(smart_str *buf, zval **struc, zval *retval_p
smart_str_appendl(buf,"N;", 2);
continue;
}
-
- php_var_serialize_string(buf, Z_STRVAL_PP(name), Z_STRLEN_PP(name));
-
if (zend_hash_find(Z_OBJPROP_PP(struc), Z_STRVAL_PP(name),
Z_STRLEN_PP(name) + 1, (void *) &d) == SUCCESS) {
- php_var_serialize_intern(buf, d, var_hash TSRMLS_CC);
+ php_var_serialize_string(buf, Z_STRVAL_PP(name), Z_STRLEN_PP(name));
+ php_var_serialize_intern(buf, d, var_hash TSRMLS_CC);
} else {
- php_var_serialize_intern(buf, &nvalp, var_hash TSRMLS_CC);
+ zend_class_entry *ce;
+ ce = zend_get_class_entry(*struc TSRMLS_CC);
+ if (ce) {
+ char *prot_name, *priv_name;
+ int prop_name_length;
+
+ do {
+ zend_mangle_property_name(&priv_name, &prop_name_length, ce->name, ce->name_length,
+ Z_STRVAL_PP(name), Z_STRLEN_PP(name) + 1, ce->type & ZEND_INTERNAL_CLASS);
+ if (zend_hash_find(Z_OBJPROP_PP(struc), priv_name, prop_name_length, (void *) &d) == SUCCESS) {
+ php_var_serialize_string(buf, priv_name, prop_name_length-1);
+ php_var_serialize_intern(buf, d, var_hash TSRMLS_CC);
+ break;
+ }
+ zend_mangle_property_name(&prot_name, &prop_name_length, "*", 1,
+ Z_STRVAL_PP(name), Z_STRLEN_PP(name) + 1, ce->type & ZEND_INTERNAL_CLASS);
+ if (zend_hash_find(Z_OBJPROP_PP(struc), prot_name, prop_name_length, (void *) &d) == SUCCESS) {
+ php_var_serialize_string(buf, prot_name, prop_name_length - 1);
+ php_var_serialize_intern(buf, d, var_hash TSRMLS_CC);
+ break;
+ }
+ php_error_docref(NULL TSRMLS_CC, E_NOTICE, "\"%s\" returned as member variable from __sleep() but does not exist", Z_STRVAL_PP(name));
+ php_var_serialize_string(buf, Z_STRVAL_PP(name), Z_STRLEN_PP(name));
+ php_var_serialize_intern(buf, &nvalp, var_hash TSRMLS_CC);
+ } while (0);
+ } else {
+ php_var_serialize_string(buf, Z_STRVAL_PP(name), Z_STRLEN_PP(name));
+ php_var_serialize_intern(buf, &nvalp, var_hash TSRMLS_CC);
+ }
}
}
}