Index: /branches/1.2/ChangeLog
===================================================================
--- /branches/1.2/ChangeLog	(revision 407)
+++ /branches/1.2/ChangeLog	(revision 408)
@@ -5,4 +5,5 @@
 == ChangeLog ==
  * #86: remove/edit variable in admin page
+ * fixed #92: Zend Optimizer compatibility issue
  * fixed #77: hits/misses was not updated
  * fixed #59: pass by reference for internal function was broken
Index: /branches/1.2/NEWS
===================================================================
--- /branches/1.2/NEWS	(revision 407)
+++ /branches/1.2/NEWS	(revision 408)
@@ -1,9 +1,9 @@
 1.2.1 2007-?-?
+========
+ * full Zend Optimizer compatibility
  * ini settings changed
- * bug fixes
+ * other bug fixes
 
-========
 1.2.0 2006-12-10
-NEWS
 ========
  * full 5.2 support
Index: /branches/1.2/utils.c
===================================================================
--- /branches/1.2/utils.c	(revision 407)
+++ /branches/1.2/utils.c	(revision 408)
@@ -630,5 +630,5 @@
 }
 /* }}} */
-static void xc_sandbox_install(xc_sandbox_t *sandbox TSRMLS_DC) /* {{{ */
+static void xc_sandbox_install(xc_sandbox_t *sandbox, xc_install_action_t install TSRMLS_DC) /* {{{ */
 {
 	int i;
@@ -674,7 +674,9 @@
 #endif
 
-	xc_undo_pass_two(CG(active_op_array) TSRMLS_CC);
-	xc_foreach_early_binding_class(CG(active_op_array), xc_early_binding_cb, (void *) sandbox TSRMLS_CC);
-	xc_redo_pass_two(CG(active_op_array) TSRMLS_CC);
+	if (install != XC_InstallNoBinding) {
+		xc_undo_pass_two(CG(active_op_array) TSRMLS_CC);
+		xc_foreach_early_binding_class(CG(active_op_array), xc_early_binding_cb, (void *) sandbox TSRMLS_CC);
+		xc_redo_pass_two(CG(active_op_array) TSRMLS_CC);
+	}
 
 	i = 1;
@@ -682,5 +684,5 @@
 }
 /* }}} */
-void xc_sandbox_free(xc_sandbox_t *sandbox, int install TSRMLS_DC) /* {{{ */
+void xc_sandbox_free(xc_sandbox_t *sandbox, xc_install_action_t install TSRMLS_DC) /* {{{ */
 {
 	/* restore first first install function/class */
@@ -695,9 +697,9 @@
 #endif
 
-	if (install) {
+	if (install != XC_NoInstall) {
 		CG(in_compilation)    = 1;
 		CG(compiled_filename) = sandbox->filename;
 		CG(zend_lineno)       = 0;
-		xc_sandbox_install(sandbox TSRMLS_CC);
+		xc_sandbox_install(sandbox, install TSRMLS_CC);
 		CG(in_compilation)    = 0;
 		CG(compiled_filename) = NULL;
Index: /branches/1.2/utils.h
===================================================================
--- /branches/1.2/utils.h	(revision 407)
+++ /branches/1.2/utils.h	(revision 408)
@@ -57,5 +57,11 @@
 } xc_sandbox_t;
 
+typedef enum _xc_install_action_t {
+    XC_NoInstall,
+    XC_Install,
+    XC_InstallNoBinding
+} xc_install_action_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);
+void xc_sandbox_free(xc_sandbox_t *sandbox, xc_install_action_t install TSRMLS_DC);
Index: /branches/1.2/xcache.c
===================================================================
--- /branches/1.2/xcache.c	(revision 407)
+++ /branches/1.2/xcache.c	(revision 408)
@@ -98,4 +98,5 @@
 
 static zend_bool xc_initized = 0;
+static zend_compile_file_t *origin_compile_file = NULL;
 static zend_compile_file_t *old_compile_file = NULL;
 static zend_llist_element  *xc_llist_zend_extension = NULL;
@@ -838,4 +839,10 @@
 }
 /* }}} */
+static zend_op_array *xc_check_initial_compile_file(zend_file_handle *h, int type TSRMLS_DC) /* {{{ */
+{
+	XG(initial_compile_file_called) = 1;
+	return origin_compile_file(h, type TSRMLS_CC);
+}
+/* }}} */
 static zend_op_array *xc_compile_file(zend_file_handle *h, int type TSRMLS_DC) /* {{{ */
 {
@@ -941,4 +948,5 @@
 	old_constinfo_cnt  = zend_hash_num_elements(EG(zend_constants));
 
+	XG(initial_compile_file_called) = 0;
 	zend_try {
 		op_array = old_compile_file(h, type TSRMLS_CC);
@@ -954,4 +962,9 @@
 		goto err_oparray;
 	}
+
+	if (!XG(initial_compile_file_called)) {
+		xc_sandbox_free(&sandbox, XC_InstallNoBinding TSRMLS_CC);
+        return op_array;
+    }
 
 	filename = h->opened_path ? h->opened_path : h->filename;
@@ -1125,13 +1138,13 @@
 	if (xc_test && stored_xce) {
 		/* free it, no install. restore now */
-		xc_sandbox_free(&sandbox, 0 TSRMLS_CC);
+		xc_sandbox_free(&sandbox, XC_NoInstall TSRMLS_CC);
 	}
 	else if (!op_array) {
 		/* failed to compile free it, no install */
-		xc_sandbox_free(&sandbox, 0 TSRMLS_CC);
+		xc_sandbox_free(&sandbox, XC_NoInstall TSRMLS_CC);
 	}
 	else {
 		CG(active_op_array) = op_array;
-		xc_sandbox_free(&sandbox, 1 TSRMLS_CC);
+		xc_sandbox_free(&sandbox, XC_Install TSRMLS_CC);
 	}
 
@@ -1378,4 +1391,9 @@
 		zend_compile_file = old_compile_file;
 		old_compile_file = NULL;
+	}
+
+	if (origin_compile_file) {
+		zend_compile_file = origin_compile_file;
+		origin_compile_file = NULL;
 	}
 
@@ -2746,5 +2764,5 @@
 #endif
 /* }}} */
-static startup_func_t xc_last_ext_startup = NULL;
+static startup_func_t xc_last_ext_startup;
 static int xc_zend_startup_last(zend_extension *extension) /* {{{ */
 {
@@ -2767,4 +2785,10 @@
 {
 	xc_zend_extension_gotup = 1;
+
+	if (!origin_compile_file) {
+		origin_compile_file = zend_compile_file;
+		zend_compile_file = xc_check_initial_compile_file;
+	}
+
 	if (zend_llist_count(&zend_extensions) > 1) {
 		zend_llist_position lpos;
Index: /branches/1.2/xcache_globals.h
===================================================================
--- /branches/1.2/xcache_globals.h	(revision 407)
+++ /branches/1.2/xcache_globals.h	(revision 408)
@@ -1,4 +1,5 @@
 
 ZEND_BEGIN_MODULE_GLOBALS(xcache)
+	zend_bool initial_compile_file_called; /* true is origin_compile_file is called */
 	zend_bool cacher;      /* true if enabled */
 	zend_bool stat;
