 +	zend_op *opline = EX(opline);
 +	zend_class_entry *ce = EX_T(opline->op1.u.var).class_entry;
 +
-+	/* Calculate the short name from the long one if no alias is supplied */
-+	if (opline->op2.op_type == IS_UNUSED) {
-+		char *tmp = strrchr(ce->name, '~');
-+
-+		if (!tmp) {
-+			zend_error(E_COMPILE_ERROR, "Cannot import %s which is not contained in a package", ce->name);
-+			/* Bails out */
++	switch (opline->op2.op_type) {
++		/* This is the case for:
++		 *   import package~ClassName;
++		 *   import $classname;
++		 * Calculate the short name from the long one
++		 */
++		case IS_UNUSED: {
++			char *tmp = strrchr(ce->name, '~');
++
++			if (!tmp) {
++				zend_error(E_COMPILE_ERROR, "Cannot import %s which is not contained in a package", ce->name);
++				/* Bails out */
++			}
++
++			alias_len = strlen(tmp)- 1;		
++			alias_name = zend_str_tolower_dup(tmp+ 1, alias_len);
++			break;
 +		}
 +
-+		alias_len = strlen(tmp)- 1;		
-+		alias_name = zend_str_tolower_dup(tmp+ 1, alias_len);
-+	} else {
-+		alias_name = zend_str_tolower_dup(opline->op2.u.constant.value.str.val, opline->op2.u.constant.value.str.len);
-+		alias_len = opline->op2.u.constant.value.str.len;
++		/* This is the case for:
++		 *   import package~ClassName as ShortName;
++		 *   import $classname as ShortName;
++		 * Use the short name supplied.
++		 */
++		case IS_CONST: {
++			alias_name = zend_str_tolower_dup(opline->op2.u.constant.value.str.val, opline->op2.u.constant.value.str.len);
++			alias_len = opline->op2.u.constant.value.str.len;
++			break;
++		}
++
++		/* This is the case for:
++		 *   import package~ClassName as $shortname;
++		 *   import $classname as $shortname;
++		 * Use the short name supplied by the variable
++		 */
++		default: {
++			zend_free_op free_op2;
++			zval *class_name = get_zval_ptr(&opline->op2, EX(Ts), &free_op2, BP_VAR_R);
++			
++			convert_to_string(class_name);
++
++			if (memchr(Z_STRVAL_P(class_name), '~', Z_STRLEN_P(class_name))) {
++				zend_error(E_COMPILE_ERROR, "Cannot import %s into a package", ce->name);
++				/* Bails out */
++			}
++
++			alias_name = zend_str_tolower_dup(Z_STRVAL_P(class_name), Z_STRLEN_P(class_name));
++			alias_len = Z_STRLEN_P(class_name);
++
++			FREE_OP(free_op2);
++			break;
++		}
 +	}
 +
 +	ce->refcount++;

+;
+
+import:
+		class_name_reference	            { zend_do_import(&$1, NULL TSRMLS_CC); }
+	|	class_name_reference T_AS T_STRING  { zend_do_import(&$1, &$3 TSRMLS_CC); }
+;
 
 additional_catches:
 		non_empty_additional_catches { $$ = $1; }
@@ -262,6 +280,18 @@
 		unticked_class_declaration_statement	{ zend_do_ticks(TSRMLS_C); }
 ;
 

retrieving revision 1.109
diff -u -r1.109 zend_opcode.c
--- Zend/zend_opcode.c	4 Oct 2004 19:54:34 -0000	1.109
+++ Zend/zend_opcode.c	4 Nov 2004 12:08:30 -0000
@@ -78,6 +78,9 @@
 	op_array->doc_comment = NULL;
 	op_array->doc_comment_len = 0;
