Project

General

Profile

Actions

Bug #60174

closed

Singleton instance w/ GeneralUtility::makeInstance

Added by Jan Runte over 10 years ago. Updated about 6 years ago.

Status:
Closed
Priority:
Must have
Assignee:
-
Category:
-
Target version:
Start date:
2014-07-08
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
6.2
PHP Version:
5.4
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

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!

Actions

Also available in: Atom PDF