Project

General

Profile

Actions

Bug #60174

closed

Singleton instance w/ GeneralUtility::makeInstance

Added by Jan Runte almost 10 years ago. Updated over 5 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 #1

Updated by Jan Runte almost 10 years ago

  • Target version changed from 7.0 to next-patchlevel
Actions #2

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

Actions #3

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...

Actions #4

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

Actions #5

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

Actions #6

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

Actions #7

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

Actions #8

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

Actions #9

Updated by Wouter Wolters over 9 years ago

  • Status changed from Under Review to Resolved
Actions #10

Updated by Benni Mack over 5 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF