Index: /trunk/utils.c
===================================================================
--- /trunk/utils.c	(revision 344)
+++ /trunk/utils.c	(revision 345)
@@ -530,4 +530,14 @@
 /* }}} */
 #endif
+
+void xc_zend_class_add_ref(zend_class_entry ZESW(*ce, **ce))
+{
+#ifdef ZEND_ENGINE_2
+	(*ce)->refcount++;
+#else
+	(*ce->refcount)++;
+#endif
+}
+
 xc_sandbox_t *xc_sandbox_init(xc_sandbox_t *sandbox, char *filename TSRMLS_DC) /* {{{ */
 {
@@ -572,10 +582,10 @@
 	h = OG(function_table);
 	zend_hash_init_ex(&TG(function_table), 128, NULL, h->pDestructor, h->persistent, h->bApplyProtection);
-	zend_hash_copy(&TG(function_table), &XG(internal_function_table), NULL, (void *) &tmp_func, sizeof(tmp_func));
+	zend_hash_copy(&TG(function_table), &XG(internal_function_table), (copy_ctor_func_t) function_add_ref, (void *) &tmp_func, sizeof(tmp_func));
 	TG(internal_class_tail) = TG(function_table).pListTail;
 
 	h = OG(class_table);
 	zend_hash_init_ex(&TG(class_table),     16, NULL, h->pDestructor, h->persistent, h->bApplyProtection);
-	zend_hash_copy(&TG(class_table), &XG(internal_class_table), NULL, (void *) &tmp_cest, sizeof(tmp_cest));
+	zend_hash_copy(&TG(class_table), &XG(internal_class_table), (copy_ctor_func_t) xc_zend_class_add_ref, (void *) &tmp_cest, sizeof(tmp_cest));
 	TG(internal_class_tail) = TG(class_table).pListTail;
 
Index: /trunk/utils.h
===================================================================
--- /trunk/utils.h	(revision 344)
+++ /trunk/utils.h	(revision 345)
@@ -75,4 +75,5 @@
 } xc_sandbox_t;
 
+void xc_zend_class_add_ref(zend_class_entry ZESW(*ce, **ce));
 xc_sandbox_t *xc_sandbox_init(xc_sandbox_t *sandbox, char *filename TSRMLS_DC);
 void xc_sandbox_free(xc_sandbox_t *sandbox, int install TSRMLS_DC);
Index: /trunk/xcache.c
===================================================================
--- /trunk/xcache.c	(revision 344)
+++ /trunk/xcache.c	(revision 345)
@@ -1610,8 +1610,8 @@
 
 		zend_hash_init_ex(&XG(internal_function_table), 100, NULL, NULL, 1, 0);
-		zend_hash_copy(&XG(internal_function_table), CG(function_table), NULL, &tmp_func, sizeof(tmp_func));
+		zend_hash_copy(&XG(internal_function_table), CG(function_table), (copy_ctor_func_t) function_add_ref, &tmp_func, sizeof(tmp_func));
 
 		zend_hash_init_ex(&XG(internal_class_table), 10, NULL, NULL, 1, 0);
-		zend_hash_copy(&XG(internal_class_table), CG(class_table), NULL, &tmp_cest, sizeof(tmp_cest));
+		zend_hash_copy(&XG(internal_class_table), CG(class_table), (copy_ctor_func_t) xc_zend_class_add_ref, &tmp_cest, sizeof(tmp_cest));
 	}
 	if (xc_php_hcache.size && !XG(php_holds)) {
