Skip to content

Commit af4cee6

Browse files
bug #62544 [DependencyInjection] Ensure deprecation detection does not trigger a PHP error (bnf)
This PR was merged into the 7.4 branch. Discussion ---------- [DependencyInjection] Ensure deprecation detection does not trigger a PHP error `Exception Interface "TYPO3\CMS\Reports\StatusProviderInterface" not found` See https://forge.typo3.org/issues/108349 | Q | A | ------------- | --- | Branch? | 7.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #62589 | License | MIT The `class_exists` check and the condition `$definition instanceof ChildDefinition` have been swapped with #61215 in order to produce an error if a service is not available. This error was later relaxed in #61270, but the executing order of the condition kept to be `class_exists` first, then `instanceof`. That means, if `class_exists` fails with a PHP error (like PHP Fatal Error: Interface "My\Vendor\MyInterface" not found`) affected uses will not see the deprecation, but a fatal error instead. Commits ------- 662d28f [DependencyInjection] Ensure deprecation detection does not trigger a PHP error
2 parents f0c6c79 + 662d28f commit af4cee6

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/Symfony/Component/DependencyInjection/Compiler/ResolveClassPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function process(ContainerBuilder $container): void
2929
) {
3030
continue;
3131
}
32-
if (class_exists($id) || interface_exists($id, false)) {
32+
if ($container->getReflectionClass($id, false)) {
3333
$definition->setClass($id);
3434
continue;
3535
}

src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveClassPassTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,28 @@ public function testInvalidClassNameDefinition()
107107

108108
(new ResolveClassPass())->process($container);
109109
}
110+
111+
#[IgnoreDeprecations]
112+
#[Group('legacy')]
113+
public function testInvalidClassWhoseImplementedInterfaceIsMissingDefinition()
114+
{
115+
$this->expectUserDeprecationMessage('Since symfony/dependency-injection 7.4: Service id "Acme\ClassImplementsUnavailableInterface" looks like a FQCN but no corresponding class or interface exists. To resolve this ambiguity, please rename this service to a non-FQCN (e.g. using dots), or create the missing class or interface.');
116+
117+
$autoloader = function (string $class) {
118+
if ('Acme\ClassImplementsUnavailableInterface' === $class) {
119+
new class implements UnavailableInterface {};
120+
}
121+
};
122+
123+
spl_autoload_register($autoloader);
124+
125+
try {
126+
$container = new ContainerBuilder();
127+
$container->register('Acme\ClassImplementsUnavailableInterface');
128+
129+
(new ResolveClassPass())->process($container);
130+
} finally {
131+
spl_autoload_unregister($autoloader);
132+
}
133+
}
110134
}

0 commit comments

Comments
 (0)