Bug #60174
closedSingleton instance w/ GeneralUtility::makeInstance
0%
Description
You cannot always get a "unique" singleton class with "GeneralUtility::makeInstance".
The static method doesn't check for an existing backslash at the beginning of "className".
use TYPO3\CMS\Core\Utility\GeneralUtility;
$singleton1 = GeneralUtility::makeInstance('TYPO3\CMS\Core\Page\PageRenderer');
$singleton2 = GeneralUtility::makeInstance('\TYPO3\CMS\Core\Page\PageRenderer');
$hash1 = spl_object_hash($singleton1);
$hash2 = spl_object_hash($singleton2);
var_dump( ($hash1 === $hash2) );
The result is FALSE. This shouldn't happen!
Updated by Jan Runte almost 10 years ago
- Target version changed from 7.0 to next-patchlevel
Updated by Helmut Hummel over 9 years ago
Jan Runte wrote:
$singleton2 = GeneralUtility::makeInstance('\TYPO3\CMS\Core\Page\PageRenderer');
First of all, this code is broken.
But I agree that this can happen during development and errors like that are horrible to track.
For master I would suggest to throw an exception in this case to notify the developers about their broken code.
For 6.2 I suggest to silently fix this case by adding $className = ltrim($className, '\\') as we should not break code that already works on a released branch
Updated by Helmut Hummel over 9 years ago
We must do the same for the Extbase ObjectManager btw. as it also keeps track of singletons...
Updated by Gerrit Code Review over 9 years ago
- Status changed from New to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/35751
Updated by Gerrit Code Review over 9 years ago
Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/35751
Updated by Gerrit Code Review over 9 years ago
Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/35751
Updated by Gerrit Code Review over 9 years ago
Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/35751
Updated by Gerrit Code Review over 9 years ago
Patch set 1 for branch TYPO3_6-2 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/35836
Updated by Wouter Wolters over 9 years ago
- Status changed from Under Review to Resolved