[BUGFIX] Fix side effect for new class instantiation 40/26440/3
authorHelmut Hummel <helmut.hummel@typo3.org>
Sun, 15 Dec 2013 18:54:46 +0000 (19:54 +0100)
committerGeorg Ringer <georg.ringer@gmail.com>
Mon, 16 Dec 2013 14:42:32 +0000 (15:42 +0100)
With commit 6eb7a54 performance optimized class
instantiation code has been committed. This code
removed the side effect of a reflection exception
being thrown when a not existing class is instantiated.

Code in ContentObjectRenderer relied on this side
effect, so we have to fix that and properly test
if the class exists instead.

Additionally this change adds some more comments
to the new instantiation code that has been forgotten
in the last commit.

Resolves: #54425
Releases: 6.2
Change-Id: I8962434d60f80daf77ccdce7a8148e26f8fee267
Reviewed-on: https://review.typo3.org/26440
Reviewed-by: Marcin S?gol
Tested-by: Marcin S?gol
Reviewed-by: Markus Klein
Reviewed-by: Stefan Neufeind
Tested-by: Anja Leichsenring
Reviewed-by: Anja Leichsenring
Tested-by: Tobias Liegl
Reviewed-by: Frans Saris
Tested-by: Frans Saris
Reviewed-by: Dmitry Dulepov
Tested-by: Dmitry Dulepov
Reviewed-by: Georg Ringer
Tested-by: Georg Ringer
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php

index 7f87ccc..77f7070 100644 (file)
@@ -4158,8 +4158,8 @@ Connection: close
        /**
         * Speed optimized alternative to ReflectionClass::newInstanceArgs()
         *
-        * @param string $className
-        * @param array $arguments
+        * @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) {
@@ -4192,6 +4192,9 @@ Connection: close
                                $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);
@@ -4202,7 +4205,7 @@ Connection: close
 
        /**
         * Returns the class name for a new instance, taking into account
-        * registered implemetations for this class
+        * registered implementations for this class
         *
         * @param string $className Base class name to evaluate
         * @return string Final class name to instantiate with "new [classname]
index 3aa9bbf..8b8c616 100644 (file)
@@ -816,12 +816,13 @@ class ContentObjectRenderer {
                );
                $name = $classMapping[$name];
                if (!array_key_exists($name, $this->contentObjects)) {
-                       try {
+                       $fullyQualifiedClassName = 'TYPO3\\CMS\\Frontend\\ContentObject\\' . $name . 'ContentObject';
+                       if (class_exists($fullyQualifiedClassName)) {
                                $this->contentObjects[$name] = GeneralUtility::makeInstance(
-                                       'TYPO3\\CMS\\Frontend\\ContentObject\\' . $name . 'ContentObject',
+                                       $fullyQualifiedClassName,
                                        $this
                                );
-                       } catch (\ReflectionException $e) {
+                       } else {
                                $this->contentObjects[$name] = NULL;
                        }
                }