From 942366bc31bf3ee945573d42fde337bcb3a928ee Mon Sep 17 00:00:00 2001 From: Helmut Hummel <helmut.hummel@typo3.org> Date: Sun, 15 Dec 2013 19:54:46 +0100 Subject: [PATCH] [BUGFIX] Fix side effect for new class instantiation 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 | 9 ++++++--- .../Classes/ContentObject/ContentObjectRenderer.php | 7 ++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/typo3/sysext/core/Classes/Utility/GeneralUtility.php b/typo3/sysext/core/Classes/Utility/GeneralUtility.php index 7f87ccc69fa5..77f70709cb20 100644 --- a/typo3/sysext/core/Classes/Utility/GeneralUtility.php +++ b/typo3/sysext/core/Classes/Utility/GeneralUtility.php @@ -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] diff --git a/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php b/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php index 3aa9bbf84d60..8b8c61668c68 100644 --- a/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php +++ b/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php @@ -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; } } -- GitLab