Issue Bug Closed

#60174Singleton instance w/ GeneralUtility::makeInstance

Jan Runte 07/08/14, 10:42 updated 10/02/18, 11:54

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!

Reviews 2