Issue Bug Closed

#62212ClassLoader: Check for Interfaces

Dominik J. 10/14/14, 14:00 updated 10/02/18, 11:51

Description

Today I was faced with an issue with YAG (see here: https://forge.typo3.org/issues/62207). I was able to resolve the issue by changing one line in the Typo3 CMS Core of Version 6.2.5 (which I believe is the most recent one).

The problem is that PHP’s require_once doesn’t work with relative paths. The SystemEnvironmentBuilder includes the interface SingletonInterface like this:

require_once __DIR__ . '/../SingletonInterface.php';

The ClassLoader (typo3/sysext/core/Classes/Core/ClassLoader.php) uses an absolute path instead. To PHP it seems like two separate files.

In line 182 of the ClassLoader.php it is first checked whether the class is already available, else it will be required (with require_once):

$loadingSuccessful = class_exists($classLoadingInformation[1], FALSE) || (bool)require_once $classLoadingInformation[0];

Unfortunately, SingletonInterface is NOT a class but an interface, and class_exists doesn’t check for interfaces. So I added the check manually:

$loadingSuccessful = class_exists($classLoadingInformation[1], FALSE) || interface_exists($classLoadingInformation[1], FALSE) || (bool)require_once $classLoadingInformation[0];

With this change the error of a redeclared “class” is resolved.

Maybe some Core Developer would consider applying my patch into the next update, as it’s only a small change that shouldn’t break with other code.

Reviews 2