PHP_FUNCTION(spl_object_hash)
{
zval *obj;
- int len;
- char *hash;
- char md5str[33];
- PHP_MD5_CTX context;
- unsigned char digest[16];
+ char* md5str;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &obj) == FAILURE) {
return;
}
+ md5str = emalloc(33);
+ php_spl_object_hash(obj, md5str TSRMLS_CC);
+
+ RETVAL_STRING(md5str, 0);
+}
+/* }}} */
+
+PHPAPI void php_spl_object_hash(zval *obj, char *md5str TSRMLS_DC) /* {{{*/
+{
+ int len;
+ char *hash;
+ PHP_MD5_CTX context;
+ unsigned char digest[16];
+
len = spprintf(&hash, 0, "%p:%d", Z_OBJ_HT_P(obj), Z_OBJ_HANDLE_P(obj));
md5str[0] = '\0';
PHP_MD5Update(&context, (unsigned char*)hash, len);
PHP_MD5Final(digest, &context);
make_digest(md5str, digest);
- RETVAL_STRING(md5str, 1);
efree(hash);
}
+/* }}} */
int spl_build_class_list_string(zval **entry, char **list TSRMLS_DC) /* {{{ */
{
PHP_FUNCTION(class_parents);
PHP_FUNCTION(class_implements);
+PHPAPI void php_spl_object_hash(zval *obj, char* md5str TSRMLS_DC);
+
#endif /* PHP_SPL_H */
/*
}
/* }}} */
+static HashTable* spl_object_storage_debug_infos(zval *obj, int *is_temp TSRMLS_DC) /* {{{ */
+{
+ spl_SplObjectStorage *intern = (spl_SplObjectStorage*)zend_object_store_get_object(obj TSRMLS_CC);
+ HashTable *rv, *props;
+ HashPosition pos;
+ zval *tmp, *storage, **entry;
+ char md5str[33], *name;
+ int name_len;
+ zstr zname, zclass, zprop;
+
+ *is_temp = 1;
+
+ props = Z_OBJPROP_P(obj);
+ ALLOC_HASHTABLE(rv);
+ ZEND_INIT_SYMTABLE_EX(rv, zend_hash_num_elements(props) + 1, 0);
+
+ zend_hash_copy(rv, props, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
+
+ MAKE_STD_ZVAL(storage);
+ array_init(storage);
+
+ zend_hash_internal_pointer_reset_ex(&intern->storage, &pos);
+ while (zend_hash_get_current_data_ex(&intern->storage, (void **)&entry, &pos) == SUCCESS) {
+ php_spl_object_hash(*entry, md5str TSRMLS_CC);
+ zval_add_ref(entry);
+ add_assoc_zval_ex(storage, md5str, 33, *entry);
+ zend_hash_move_forward_ex(&intern->storage, &pos);
+ }
+
+ if (UG(unicode)) {
+ zclass.u = USTR_MAKE("SplObjectStorage");
+ zprop.u = USTR_MAKE("storage");
+ zend_u_mangle_property_name(&zname, &name_len, IS_UNICODE, zclass, sizeof("SplObjectStorage")-1, zprop, sizeof("storage")-1, 0);
+ zend_u_symtable_update(rv, IS_UNICODE, zname, name_len+1, &storage, sizeof(zval *), NULL);
+ efree(zname.v);
+ efree(zclass.v);
+ efree(zprop.v);
+ } else {
+ zend_mangle_property_name(&name, &name_len, "SplObjectStorage", sizeof("SplObjectStorage")-1, "storage", sizeof("storage")-1, 0);
+ zend_symtable_update(rv, name, name_len+1, &storage, sizeof(zval *), NULL);
+ efree(name);
+ }
+
+ return rv;
+}
+/* }}} */
+
/* {{{ spl_array_object_new */
static zend_object_value spl_SplObjectStorage_new(zend_class_entry *class_type TSRMLS_DC)
{
REGISTER_SPL_STD_CLASS_EX(SplObjectStorage, spl_SplObjectStorage_new, spl_funcs_SplObjectStorage);
memcpy(&spl_handler_SplObjectStorage, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
+ spl_handler_SplObjectStorage.get_debug_info = spl_object_storage_debug_infos;
REGISTER_SPL_IMPLEMENTS(SplObjectStorage, Countable);
REGISTER_SPL_IMPLEMENTS(SplObjectStorage, Iterator);
int(2)
int(1)
int(2)
-object(MyStorage)#%d (1) {
+object(MyStorage)#%d (2) {
["bla"]=>
int(26)
+ ["storage":"SplObjectStorage":private]=>
+ array(2) {
+ ["%s"]=>
+ object(TestClass)#%d (1) {
+ ["test"]=>
+ int(1)
+ }
+ ["%s"]=>
+ object(TestClass)#%d (1) {
+ ["test"]=>
+ int(2)
+ }
+ }
}
string(%d) "%s"
===UNSERIALIZE===
int(2)
int(1)
int(2)
-object(MyStorage)#%d (1) {
+object(MyStorage)#%d (2) {
["bla"]=>
int(26)
+ ["storage":"SplObjectStorage":private]=>
+ array(2) {
+ ["%s"]=>
+ object(TestClass)#%d (1) {
+ ["test"]=>
+ int(1)
+ }
+ ["%s"]=>
+ object(TestClass)#%d (1) {
+ ["test"]=>
+ int(2)
+ }
+ }
}
===DONE===
--UEXPECTF--
int(2)
int(1)
int(2)
-object(MyStorage)#%d (1) {
+object(MyStorage)#%d (2) {
[u"bla"]=>
int(26)
+ [u"storage":u"SplObjectStorage":private]=>
+ array(2) {
+ ["%s"]=>
+ object(TestClass)#%d (1) {
+ [u"test"]=>
+ int(1)
+ }
+ ["%s"]=>
+ object(TestClass)#%d (1) {
+ [u"test"]=>
+ int(2)
+ }
+ }
}
unicode(%d) "%s"
===UNSERIALIZE===
int(2)
int(1)
int(2)
-object(MyStorage)#%d (1) {
+object(MyStorage)#%d (2) {
[u"bla"]=>
int(26)
+ [u"storage":u"SplObjectStorage":private]=>
+ array(2) {
+ ["%s"]=>
+ object(TestClass)#%d (1) {
+ [u"test"]=>
+ int(1)
+ }
+ ["%s"]=>
+ object(TestClass)#%d (1) {
+ [u"test"]=>
+ int(2)
+ }
+ }
}
===DONE===
["pri":"TestClass":private]=>
int(9)
}
-object(MyStorage)#%d (4) {
+object(MyStorage)#%d (5) {
["def"]=>
int(24)
["pub"]=>
int(2)
["pri":"MyStorage":private]=>
int(3)
+ ["storage":"SplObjectStorage":private]=>
+ array(2) {
+ ["%s"]=>
+ object(TestClass)#%d (4) {
+ ["def"]=>
+ int(24)
+ ["pub"]=>
+ int(4)
+ ["pro":protected]=>
+ int(5)
+ ["pri":"TestClass":private]=>
+ int(6)
+ }
+ ["%s"]=>
+ object(TestClass)#%d (4) {
+ ["def"]=>
+ int(24)
+ ["pub"]=>
+ int(7)
+ ["pro":protected]=>
+ int(8)
+ ["pri":"TestClass":private]=>
+ int(9)
+ }
+ }
}
string(%d) "%s"
===UNSERIALIZE===
["pri":"TestClass":private]=>
int(9)
}
-object(MyStorage)#%d (4) {
+object(MyStorage)#%d (5) {
["def"]=>
int(24)
["pub"]=>
int(2)
["pri":"MyStorage":private]=>
int(3)
+ ["storage":"SplObjectStorage":private]=>
+ array(2) {
+ ["%s"]=>
+ object(TestClass)#%d (4) {
+ ["def"]=>
+ int(24)
+ ["pub"]=>
+ int(4)
+ ["pro":protected]=>
+ int(5)
+ ["pri":"TestClass":private]=>
+ int(6)
+ }
+ ["%s"]=>
+ object(TestClass)#%d (4) {
+ ["def"]=>
+ int(24)
+ ["pub"]=>
+ int(7)
+ ["pro":protected]=>
+ int(8)
+ ["pri":"TestClass":private]=>
+ int(9)
+ }
+ }
}
===DONE===
--UEXPECTF--
[u"pri":u"TestClass":private]=>
int(9)
}
-object(MyStorage)#%d (4) {
+object(MyStorage)#%d (5) {
[u"def"]=>
int(24)
[u"pub"]=>
int(2)
[u"pri":u"MyStorage":private]=>
int(3)
+ [u"storage":u"SplObjectStorage":private]=>
+ array(2) {
+ ["%s"]=>
+ object(TestClass)#%d (4) {
+ [u"def"]=>
+ int(24)
+ [u"pub"]=>
+ int(4)
+ [u"pro":protected]=>
+ int(5)
+ [u"pri":u"TestClass":private]=>
+ int(6)
+ }
+ ["%s"]=>
+ object(TestClass)#%d (4) {
+ [u"def"]=>
+ int(24)
+ [u"pub"]=>
+ int(7)
+ [u"pro":protected]=>
+ int(8)
+ [u"pri":u"TestClass":private]=>
+ int(9)
+ }
+ }
}
unicode(%d) "%s"
===UNSERIALIZE===
[u"pri":u"TestClass":private]=>
int(9)
}
-object(MyStorage)#%d (4) {
+object(MyStorage)#%d (5) {
[u"def"]=>
int(24)
[u"pub"]=>
int(2)
[u"pri":u"MyStorage":private]=>
int(3)
+ [u"storage":u"SplObjectStorage":private]=>
+ array(2) {
+ ["%s"]=>
+ object(TestClass)#%d (4) {
+ [u"def"]=>
+ int(24)
+ [u"pub"]=>
+ int(4)
+ [u"pro":protected]=>
+ int(5)
+ [u"pri":u"TestClass":private]=>
+ int(6)
+ }
+ ["%s"]=>
+ object(TestClass)#%d (4) {
+ [u"def"]=>
+ int(24)
+ [u"pub"]=>
+ int(7)
+ [u"pro":protected]=>
+ int(8)
+ [u"pri":u"TestClass":private]=>
+ int(9)
+ }
+ }
}
===DONE===