Index: utils.c
===================================================================
--- utils.c	(revision 563)
+++ utils.c	(working copy)
@@ -594,6 +594,14 @@
 /* }}} */
 #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) /* {{{ */
 {
 	HashTable *h;
@@ -631,6 +639,10 @@
 #ifdef HAVE_XCACHE_CONSTANT
 	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);
 	zend_hash_init_ex(&TG(function_table), 128, NULL, h->pDestructor, h->persistent, h->bApplyProtection);
@@ -678,7 +690,7 @@
 	sandbox->orig_compiler_options = CG(compiler_options);
 	/* 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
 
 	XG(sandbox) = (void *) sandbox;
@@ -697,7 +709,7 @@
 	Bucket *b;
 
 #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) {
 		zend_constant *c = (zend_constant*) b->pData;
Index: utils.h
===================================================================
--- utils.h	(revision 563)
+++ utils.h	(working copy)
@@ -94,6 +94,9 @@
 	HashTable tmp_function_table;
 	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: xcache_globals.h
===================================================================
--- xcache_globals.h	(revision 563)
+++ xcache_globals.h	(working copy)
@@ -21,6 +21,9 @@
 	HashTable gc_op_arrays;
 #endif
 
+#ifdef HAVE_XCACHE_CONSTANT
+	HashTable internal_constant_table;
+#endif
 	HashTable internal_function_table;
 	HashTable internal_class_table;
 	zend_bool internal_table_copied;
Index: xcache.c
===================================================================
--- xcache.c	(revision 572)
+++ xcache.c	(working copy)
@@ -1848,20 +1848,40 @@
 	return 0;
 }
 /* }}} */
+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) /* {{{ */
 {
 	int i;
 
 	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));
 
@@ -1920,6 +1940,9 @@
 {
 	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);
 }
@@ -1951,6 +1974,9 @@
 	}
 
 	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);
 	}
