 +	fprintf(stderr, "Import %s => %s\n", ce->name, alias_name);
 +#endif
 +
++	/* Check if we previously imported this class. If so, ignore */
++	if (zend_hash_find(CG(class_table), alias_name, alias_len+ 1, (void **) &pce) == SUCCESS) {
++		if (*pce == ce) {
++			goto done;
++		}
++		zend_error(
++			E_COMPILE_ERROR, 
++			"Cannot import class %s as class %s (declared in %s on line %d)",
++			ce->name, 
++			(*pce)->name,
++			(*pce)->filename, 
++			(*pce)->line_start
++		);
++		/* Bails out */
++	}
++
 +	ce->refcount++;
-+	if (zend_hash_add(CG(class_table), alias_name, alias_len+ 1, &ce, sizeof(zend_class_entry *), NULL)==FAILURE) {
++	if (zend_hash_add(CG(class_table), alias_name, alias_len+ 1, &ce, sizeof(zend_class_entry *), NULL) == FAILURE) {
 +		ce->refcount--;
-+		zend_error(E_COMPILE_ERROR, "Cannot import class %s as already declared %s", ce->name, alias_name);
++		zend_error(E_CORE_ERROR, "Cannot add class %s to the class table\n", ce->name);
 +		/* Bails out */
 +	}
-+	
++
++done:	
 +	efree(alias_name);
 +	ZEND_VM_NEXT_OPCODE();
 +}

 
 void zend_vm_use_old_executor()
 {
@@ -31129,6 +31563,8 @@
   	ZEND_ASSIGN_DIM_HANDLER,
   	ZEND_ISSET_ISEMPTY_PROP_OBJ_HANDLER,
   	ZEND_HANDLE_EXCEPTION_HANDLER,

 static int ZEND_ADD_SPEC_TMP_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
 {
 	zend_op *opline = EX(opline);
@@ -5439,6 +5607,18 @@
 	return zend_init_add_array_helper_SPEC_TMP_TMP(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);
 }
 
