Index: /trunk/xcache.c
===================================================================
--- /trunk/xcache.c	(revision 780)
+++ /trunk/xcache.c	(revision 781)
@@ -2876,5 +2876,5 @@
 /* }}} */
 /* {{{ proto int xcache_get_refcount(mixed variable)
-   Get reference count of variable */
+   XCache internal uses only: Get reference count of variable */
 PHP_FUNCTION(xcache_get_refcount)
 {
@@ -2888,5 +2888,9 @@
 /* }}} */
 /* {{{ proto bool xcache_get_isref(mixed variable)
-   check if variable data is marked referenced */
+   XCache internal uses only: Check if variable data is marked referenced */
+ZEND_BEGIN_ARG_INFO_EX(arginfo_xcache_get_isref, 0, 0, 1)
+	ZEND_ARG_INFO(1, variable)
+ZEND_END_ARG_INFO()
+
 PHP_FUNCTION(xcache_get_isref)
 {
@@ -2896,5 +2900,5 @@
 	}
 
-	RETURN_BOOL(Z_ISREF_P(variable));
+	RETURN_BOOL(Z_ISREF_P(variable) && Z_REFCOUNT_P(variable) >= 3);
 }
 /* }}} */
@@ -3047,5 +3051,6 @@
 /* }}} */
 #endif
-/* {{{ proto mixed xcache_get_special_value(zval value) */
+/* {{{ proto mixed xcache_get_special_value(zval value)
+   XCache internal use only: For decompiler to get static value with type fixed */
 PHP_FUNCTION(xcache_get_special_value)
 {
@@ -3072,4 +3077,17 @@
 		RETURN_NULL();
 	}
+}
+/* }}} */
+/* {{{ proto int xcache_get_type(zval value)
+   XCache internal use only for disassembler to get variable type in engine level */
+PHP_FUNCTION(xcache_get_type)
+{
+	zval *value;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &value) == FAILURE) {
+		return;
+	}
+
+	RETURN_LONG(Z_TYPE_P(value));
 }
 /* }}} */
@@ -3126,4 +3144,5 @@
 #endif
 	PHP_FE(xcache_get_special_value, NULL)
+	PHP_FE(xcache_get_type,          NULL)
 	PHP_FE(xcache_get_op_type,       NULL)
 	PHP_FE(xcache_get_data_type,     NULL)
@@ -3141,5 +3160,5 @@
 	PHP_FE(xcache_unset_by_prefix,   NULL)
 	PHP_FE(xcache_get_refcount,      NULL)
-	PHP_FE(xcache_get_isref,         NULL)
+	PHP_FE(xcache_get_isref,         arginfo_xcache_get_isref)
 #ifdef HAVE_XCACHE_DPRINT
 	PHP_FE(xcache_dprint,            NULL)
Index: /trunk/Decompiler.class.php
===================================================================
--- /trunk/Decompiler.class.php	(revision 780)
+++ /trunk/Decompiler.class.php	(revision 781)
@@ -1141,13 +1141,20 @@
 						break;
 					}
+					if (is_a($rvalue, 'Decompiler_Fetch')) {
+						$src = str($rvalue->src, $EX);
+						if ('$' . unquoteName($src) == $lvalue) {
+							switch ($rvalue->fetchType) {
+							case ZEND_FETCH_STATIC:
+								$statics = &$EX['op_array']['static_variables'];
+								if ((xcache_get_type($statics[$name]) & IS_LEXICAL_VAR)) {
+									$EX['uses'][] = str($lvalue);
+									unset($statics);
+									break 2;
+								}
+								unset($statics);
+							}
+						}
+					}
 					$resvar = "$lvalue = " . str($rvalue, $EX);
-					if (0) {
-					if ($op2['op_type'] == XC_IS_VAR) {
-						$resvar .= ' /* isvar */';
-					}
-					else if ($op2['op_type'] == XC_IS_TMP_VAR) {
-						$resvar .= ' /* istmp */';
-					}
-					}
 					break;
 					// }}}
@@ -1165,4 +1172,10 @@
 							case ZEND_FETCH_STATIC:
 								$statics = &$EX['op_array']['static_variables'];
+								if ((xcache_get_type($statics[$name]) & IS_LEXICAL_REF)) {
+									$EX['uses'][] = '&' . str($lvalue);
+									unset($statics);
+									break 2;
+								}
+
 								$resvar = 'static ' . $lvalue;
 								$name = unquoteName($src);
@@ -1854,13 +1867,7 @@
 	function duses(&$EX, $indent) // {{{
 	{
-		if (!$EX['uses']) {
-			return;
-		}
-
-		$uses = array();
-		foreach ($EX['uses'] as $name => $value) {
-			$uses = '$' . $name;
-		}
-		echo ' use(', implode(', ', $uses), ')';
+		if ($EX['uses']) {
+			echo ' use(', implode(', ', $EX['uses']), ')';
+		}
 	}
 	// }}}
@@ -1886,5 +1893,5 @@
 			$functionName = '';
 		}
-		echo 'function ', $functionName, '(';
+		echo 'function', $functionName ? ' ' . $functionName : '', '(';
 		$this->dargs($EX, $indent);
 		echo ")";
@@ -2257,4 +2264,10 @@
 define('IS_CONSTANT', 8);
 define('IS_CONSTANT_ARRAY',   9);
+/* Ugly hack to support constants as static array indices */
+define('IS_CONSTANT_TYPE_MASK',   0x0f);
+define('IS_CONSTANT_UNQUALIFIED', 0x10);
+define('IS_CONSTANT_INDEX',       0x80);
+define('IS_LEXICAL_VAR',          0x20);
+define('IS_LEXICAL_REF',          0x40);
 
 @define('XC_IS_CV', 16);
Index: /trunk/decompilesample.php
===================================================================
--- /trunk/decompilesample.php	(revision 780)
+++ /trunk/decompilesample.php	(revision 781)
@@ -360,6 +360,8 @@
 $total = 0;
 $tax = 1;
-$callback = function ($quantity, $product) use ($tax, &$total) {
-	static $static = array(1);
+$callback = function($quantity, $product) use($tax, &$total) {
+	$tax = 'tax';
+	static $static1 = array(1);
+	static $static2;
 	$tax = 'tax';
 	$tax = --$tax;
