Revert "[TASK] Optimize speed for instantiating class with arguments" 10/26910/2
authorErnesto Baschny <ernst@cron-it.de>
Fri, 17 Jan 2014 19:18:26 +0000 (20:18 +0100)
committerErnesto Baschny <ernst@cron-it.de>
Fri, 17 Jan 2014 19:45:36 +0000 (20:45 +0100)
This reverts commit 2526bddb5b27ca832575fad809facfa39c7db225.

This is not PHP 5.2 compatible (static::*).

See also travis reporting on that:
https://travis-ci.org/TYPO3/TYPO3.CMS/jobs/17114327

Change-Id: Ia0dc0766dd73ce5343464afd1f71b1b2d8e27795
Reviewed-on: https://review.typo3.org/26910
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Ernesto Baschny
Tested-by: Ernesto Baschny
t3lib/class.t3lib_div.php
typo3/sysext/cms/tslib/class.tslib_content.php

index b6e1610..b31ebe0 100644 (file)
@@ -5367,7 +5367,15 @@ final class t3lib_div {
                }
 
                        // Create new instance and call constructor with parameters
-               $instance = static::instantiateClass($finalClassName, func_get_args());
+               if (func_num_args() > 1) {
+                       $constructorArguments = func_get_args();
+                       array_shift($constructorArguments);
+
+                       $reflectedClass = new ReflectionClass($finalClassName);
+                       $instance = $reflectedClass->newInstanceArgs($constructorArguments);
+               } else {
+                       $instance = new $finalClassName;
+               }
 
                        // Register new singleton instance
                if ($instance instanceof t3lib_Singleton) {
@@ -5393,54 +5401,6 @@ final class t3lib_div {
        }
 
        /**
-        * Speed optimized alternative to ReflectionClass::newInstanceArgs()
-        *
-        * @param string $className Name of the class to instantiate
-        * @param array $arguments Arguments passed to self::makeInstance() thus the first one with index 0 holds the requested class name
-        * @return mixed
-        */
-       protected static function instantiateClass($className, $arguments) {
-               switch (count($arguments)) {
-                       case 1:
-                               $instance = new $className();
-                               break;
-                       case 2:
-                               $instance = new $className($arguments[1]);
-                               break;
-                       case 3:
-                               $instance = new $className($arguments[1], $arguments[2]);
-                               break;
-                       case 4:
-                               $instance = new $className($arguments[1], $arguments[2], $arguments[3]);
-                               break;
-                       case 5:
-                               $instance = new $className($arguments[1], $arguments[2], $arguments[3], $arguments[4]);
-                               break;
-                       case 6:
-                               $instance = new $className($arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5]);
-                               break;
-                       case 7:
-                               $instance = new $className($arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5], $arguments[6]);
-                               break;
-                       case 8:
-                               $instance = new $className($arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5], $arguments[6], $arguments[7]);
-                               break;
-                       case 9:
-                               $instance = new $className($arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5], $arguments[6], $arguments[7], $arguments[8]);
-                               break;
-                       default:
-                               // The default case for classes with constructors that have more than 8 arguments.
-                               // This will fail when one of the arguments shall be passed by reference.
-                               // In case we really need to support this edge case, we can implement the solution from here: https://review.typo3.org/26344
-                               $class = new ReflectionClass($className);
-                               array_shift($arguments);
-                               $instance = $class->newInstanceArgs($arguments);
-                               return $instance;
-               }
-               return $instance;
-       }
-
-       /**
         * Returns the class name for a new instance, taking into account the
         * class-extension API.
         *
index 7e36ec3..166ced1 100644 (file)
@@ -847,10 +847,9 @@ class tslib_cObj {
                $name = $classMapping[$name];
 
                if (!array_key_exists($name, $this->contentObjects)) {
-                       $fullyQualifiedClassName = 'tslib_content_' . $name;
-                       if (class_exists($fullyQualifiedClassName)) {
-                               $this->contentObjects[$name] = t3lib_div::makeInstance($fullyQualifiedClassName, $this);
-                       } else {
+                       try {
+                               $this->contentObjects[$name] = t3lib_div::makeInstance('tslib_content_' . $name, $this);
+                       } catch (ReflectionException $e) {
                                $this->contentObjects[$name] = NULL;
                        }
                }