Index: sandbox/workflow/branches/609/lib/factory/BaseFactory.php
===================================================================
--- sandbox/workflow/branches/609/lib/factory/BaseFactory.php	(revision 2233)
+++ sandbox/workflow/branches/609/lib/factory/BaseFactory.php	(revision 2278)
@@ -14,4 +14,6 @@
  * This class implements all the common behaviour of
  * it's specialized classes (ProcessFactory and WorkflowFactory).
+ * The only class allowed to use it's methods should be the
+ * Factory frontend.
  *
  * @package Factory
@@ -32,5 +34,4 @@
 	 * atribute.
 	 *
-	 * @todo Maybe here we should receive more parameters...
 	 * @access protected
 	 * @return void
@@ -51,28 +52,27 @@
 	 * into our private object cache. If there is no
 	 * object of the given type into the cache, 'newInstance'
-	 * will be called.
+	 * will be called. This method must deal with
+	 * pointers (&) to avoid object duplications.
 	 *
 	 * @access public
 	 * @return object
 	 */
-	public function &getInstance(){
+	public function &getInstance($className, $classArgs){
 
-		/* at least the class name */
-		if (func_num_args() <= 0)
+		/* have we a class name? */
+		if (empty($className))
 			return null;
 
-		$args = func_get_args();
-
 		/* recovering class data */
-		if ($entry = $this->_getEntry($args[0])) {
+		if ($entry = &$this->_getEntry($className)) {
 
 			if (is_null($entry['instance'])) {
 
-				/* must instantiate it */
-                if (($obj = call_user_func_array(array($this, "newInstance"), $args)) == null)
-					throw new Exception("Unable to instantiate '".$args[0]."'");
+				/* we must instantiate it */
+                if (($obj = &$this->newInstance($className, $classArgs)) == null)
+					throw new Exception("Unable to instantiate '".$className."'");
 
 				/* saving the object reference */
-				$this->_setEntryInstance($args[0], $obj);
+				$this->_setEntryInstance($className, $obj);
 				return $obj;
 			}
@@ -82,33 +82,36 @@
 		/* class not allowed */
 		else
-			throw new Exception("You are not allowed to instantiate class '".$args[0]."'.");
+			throw new Exception("You are not allowed to instantiate class '".$className."'.");
 	}
 
 	/**
-	 * Instantiate classes.
+	 * Instantiating classes.
 	 *
-	 * @todo I think that we don't need to use the reflection
+	 * @todo Maybe we don't have to use the reflection
 	 *		 class here. Future work...
 	 * @access public
 	 * @return object
 	 */
-	public function &newInstance(){
+	public function &newInstance($className, $classArgs){
 
-		/* at least the class name */
-		if (func_num_args() <= 0)
+		/* have we a class name? */
+		if (empty($className))
 			return null;
 
-		$args = func_get_args();
-
-		$className = array_shift($args);
+		/* just to be sure. If this method fails, it will throw an exception anyway... */
 		if(!$this->_import($className))
 			return null;
 
-		/* I dont know.. maybe we could do better here.. */
+		/**
+		 * Here we use this big white elephant (by big white elephant I mean php
+		 * reflection interface) just because we have to pass an unknown number
+		 * of parameters to the constructor of the class.
+		 * If you know a better way to do this, please update this code =D
+		 */
 		$reflectionObj = new ReflectionClass($className);
 
-		if (count($args) == 0)
+		if (count($classArgs) == 0)
 			return $reflectionObj->newInstance();
-		return $reflectionObj->newInstanceArgs($args);
+		return $reflectionObj->newInstanceArgs($classArgs);
 	}
 
@@ -121,5 +124,5 @@
 	 * @return array
 	 */
-	private function _getEntry($className){
+	private function &_getEntry($className){
 		return $this->_fileInfo[$className];
 	}
@@ -133,8 +136,8 @@
 	 * @return boolean
 	 */
-	private function _setEntryInstance($className, $obj){
+	private function _setEntryInstance($className, &$obj){
 
 		if (is_array($this->_fileInfo[$className])) {
-			$this->_fileInfo[$className]['instance'] = $obj;
+			$this->_fileInfo[$className]['instance'] = &$obj;
 			return true;
 		}
Index: sandbox/workflow/branches/609/lib/factory/WorkflowFactory.php
===================================================================
--- sandbox/workflow/branches/609/lib/factory/WorkflowFactory.php	(revision 2268)
+++ sandbox/workflow/branches/609/lib/factory/WorkflowFactory.php	(revision 2278)
@@ -83,5 +83,5 @@
 		$this->registerFileInfo('common', 'class.common.inc.php', '', EGW_INC_ROOT);
 		$this->registerFileInfo('session', 'class.session.inc.php', '', EGW_INC_ROOT);
-		$this->registerFileInfo('nextmachs', 'class.nextmatchs.inc.php', '', EGW_INC_ROOT);
+		$this->registerFileInfo('nextmatchs', 'class.nextmatchs.inc.php', '', EGW_INC_ROOT);
 		$this->registerFileInfo('categories', 'class.categories.inc.php', '', EGW_INC_ROOT);
 		$this->registerFileInfo('listbox', 'class.listbox.inc.php', '', EGW_INC_ROOT);
Index: sandbox/workflow/branches/609/lib/factory/Factory.php
===================================================================
--- sandbox/workflow/branches/609/lib/factory/Factory.php	(revision 2249)
+++ sandbox/workflow/branches/609/lib/factory/Factory.php	(revision 2278)
@@ -103,5 +103,6 @@
 				self::$_unsecuredFactory = new WorkflowFactory();
 
-			return call_user_func_array(array(self::$_unsecuredFactory, $methodName), $args);
+			$className = array_shift($args);
+			return self::$_unsecuredFactory->$methodName($className, $args);
 		}
 		/* oops. we are in the process space (restricted). */
@@ -112,4 +113,6 @@
 				self::$_securedFactory = new ProcessFactory();
 
+			$className = array_shift($args);
+
 			/**
 			 * If the class is not allowed, we must check who is trying
@@ -118,5 +121,5 @@
 			 */
 			try {
-				$obj = call_user_func_array(array(self::$_securedFactory, $methodName), $args);
+				$obj = &self::$_securedFactory->$methodName($className, $args);
 			}
 
@@ -133,7 +136,7 @@
 				 */
 				if (Security::isSafeDir(2))
-					$obj = call_user_func_array(array(self::$_unsecuredFactory, $methodName), $args);
+					$obj = &self::$_unsecuredFactory->$methodName($className, $args);
 
-				/* nasty one. take this... */
+				/* naaasty one. take this! */
 				else
 					throw($e);
