Index: /trunk/utils.c
===================================================================
--- /trunk/utils.c	(revision 587)
+++ /trunk/utils.c	(revision 588)
@@ -595,4 +595,12 @@
 #endif
 
+static void xc_copy_zend_constant(zend_constant *c) /* {{{ */
+{
+	c->name = zend_strndup(c->name, c->name_len - 1);
+	if (!(c->flags & CONST_PERSISTENT)) {
+		zval_copy_ctor(&c->value);
+	}
+}
+/* }}} */
 xc_sandbox_t *xc_sandbox_init(xc_sandbox_t *sandbox, char *filename TSRMLS_DC) /* {{{ */
 {
@@ -632,4 +640,8 @@
 	h = OG(zend_constants);
 	zend_hash_init_ex(&TG(zend_constants),  20, NULL, h->pDestructor, h->persistent, h->bApplyProtection);
+	{
+		zend_constant tmp_const;
+		zend_hash_copy(&TG(zend_constants), &XG(internal_constant_table), (copy_ctor_func_t) xc_copy_zend_constant, (void *) &tmp_const, sizeof(tmp_const));
+	}
 #endif
 	h = OG(function_table);
@@ -679,5 +691,5 @@
 	/* Using ZEND_COMPILE_IGNORE_INTERNAL_CLASSES for ZEND_FETCH_CLASS_RT_NS_CHECK
 	 */
-	CG(compiler_options) |= ZEND_COMPILE_IGNORE_INTERNAL_CLASSES | ZEND_COMPILE_DELAYED_BINDING;
+	CG(compiler_options) |= ZEND_COMPILE_IGNORE_INTERNAL_CLASSES | ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION | ZEND_COMPILE_DELAYED_BINDING;
 #endif
 
@@ -698,5 +710,5 @@
 
 #ifdef HAVE_XCACHE_CONSTANT
-	b = TG(zend_constants).pListHead;
+	b = /*TG(internal_constant_tail) ? TG(internal_constant_tail)->pListNext :*/ TG(zend_constants).pListHead;
 	/* install constants */
 	while (b != NULL) {
Index: /trunk/utils.h
===================================================================
--- /trunk/utils.h	(revision 587)
+++ /trunk/utils.h	(revision 588)
@@ -95,4 +95,7 @@
 	HashTable tmp_class_table;
 	HashTable tmp_auto_globals;
+#ifdef HAVE_XCACHE_CONSTANT
+	Bucket    *tmp_internal_constant_tail;
+#endif
 	Bucket    *tmp_internal_function_tail;
 	Bucket    *tmp_internal_class_tail;
Index: /trunk/xcache.c
===================================================================
--- /trunk/xcache.c	(revision 587)
+++ /trunk/xcache.c	(revision 588)
@@ -1849,4 +1849,12 @@
 }
 /* }}} */
+static void xc_copy_zend_constant(zend_constant *c) /* {{{ */
+{
+	c->name = zend_strndup(c->name, c->name_len - 1);
+	if (!(c->flags & CONST_PERSISTENT)) {
+		zval_copy_ctor(&c->value);
+	}
+}
+/* }}} */
 static void xc_request_init(TSRMLS_D) /* {{{ */
 {
@@ -1854,13 +1862,25 @@
 
 	if (!XG(internal_table_copied)) {
+#ifdef HAVE_XCACHE_CONSTANT
+		zend_constant tmp_const;
+#endif
 		zend_function tmp_func;
 		xc_cest_t tmp_cest;
 
+#ifdef HAVE_XCACHE_CONSTANT
+		zend_hash_destroy(&XG(internal_constant_table));
+#endif
 		zend_hash_destroy(&XG(internal_function_table));
 		zend_hash_destroy(&XG(internal_class_table));
 
+#ifdef HAVE_XCACHE_CONSTANT
+		zend_hash_init_ex(&XG(internal_constant_table), 20,  NULL, NULL, 1, 0);
+#endif
 		zend_hash_init_ex(&XG(internal_function_table), 100, NULL, NULL, 1, 0);
 		zend_hash_init_ex(&XG(internal_class_table),    10,  NULL, NULL, 1, 0);
 
+#ifdef HAVE_XCACHE_CONSTANT
+		zend_hash_copy(&XG(internal_constant_table), EG(zend_constants), (copy_ctor_func_t) xc_copy_zend_constant, &tmp_const, sizeof(tmp_const));
+#endif
 		zend_hash_copy(&XG(internal_function_table), CG(function_table), NULL, &tmp_func, sizeof(tmp_func));
 		zend_hash_copy(&XG(internal_class_table), CG(class_table), NULL, &tmp_cest, sizeof(tmp_cest));
@@ -1921,4 +1941,7 @@
 	memset(xcache_globals, 0, sizeof(zend_xcache_globals));
 
+#ifdef HAVE_XCACHE_CONSTANT
+	zend_hash_init_ex(&xcache_globals->internal_constant_table, 1, NULL, NULL, 1, 0);
+#endif
 	zend_hash_init_ex(&xcache_globals->internal_function_table, 1, NULL, NULL, 1, 0);
 	zend_hash_init_ex(&xcache_globals->internal_class_table,    1, NULL, NULL, 1, 0);
@@ -1952,4 +1975,7 @@
 
 	if (xcache_globals->internal_table_copied) {
+#ifdef HAVE_XCACHE_CONSTANT
+		zend_hash_destroy(&xcache_globals->internal_constant_table);
+#endif
 		zend_hash_destroy(&xcache_globals->internal_function_table);
 		zend_hash_destroy(&xcache_globals->internal_class_table);
Index: /trunk/xcache_globals.h
===================================================================
--- /trunk/xcache_globals.h	(revision 587)
+++ /trunk/xcache_globals.h	(revision 588)
@@ -22,4 +22,7 @@
 #endif
 
+#ifdef HAVE_XCACHE_CONSTANT
+	HashTable internal_constant_table;
+#endif
 	HashTable internal_function_table;
 	HashTable internal_class_table;
