bug #41233 [DependencyInjection][ProxyManagerBridge] Don't call class_exists() on null (derrabus)

This PR was merged into the 4.4 branch.

Discussion
----------

[DependencyInjection][ProxyManagerBridge] Don't call class_exists() on null

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | N/A
| License       | MIT
| Doc PR        | N/A

PHP 8.1 complains if we pass `null` to `class_exists()` or `interface_exists()`:

> class_exists(): Passing null to parameter `#1` ($class) of type string is deprecated

Commits
-------

88520e53b2 Don't call class_exists() on null
This commit is contained in:
Nicolas Grekas 2021-05-15 10:05:00 +02:00
commit 9e12a383ee
2 changed files with 8 additions and 3 deletions

View File

@ -43,7 +43,7 @@ class LazyLoadingValueHolderGenerator extends BaseGenerator
public function getProxifiedClass(Definition $definition): ?string
{
if (!$definition->hasTag('proxy')) {
return class_exists($class = $definition->getClass()) || interface_exists($class, false) ? $class : null;
return ($class = $definition->getClass()) && (class_exists($class) || interface_exists($class, false)) ? $class : null;
}
if (!$definition->isLazy()) {
throw new \InvalidArgumentException(sprintf('Invalid definition for service of class "%s": setting the "proxy" tag on a service requires it to be "lazy".', $definition->getClass()));

View File

@ -88,8 +88,13 @@ final class CheckTypeDeclarationsPass extends AbstractRecursivePass
return parent::processValue($value, $isRoot);
}
if (!$this->autoload && !class_exists($class = $value->getClass(), false) && !interface_exists($class, false)) {
return parent::processValue($value, $isRoot);
if (!$this->autoload) {
if (!$class = $value->getClass()) {
return parent::processValue($value, $isRoot);
}
if (!class_exists($class, false) && !interface_exists($class, false)) {
return parent::processValue($value, $isRoot);
}
}
if (ServiceLocator::class === $value->getClass()) {