Skip to content

Commit 663f5dd

Browse files
Merge branch '5.0' into 5.1
* 5.0: (28 commits) [Cache] $lifetime cannot be null [Serializer] minor cleanup fix merge Run PHP 8 as 7.4.99 Remove calls to deprecated ReflectionParameter::getClass(). [VarDumper] fix PHP 8 support Add php 8 to travis. [Cache] Accessing undefined constants raises an Error in php8 [Cache] allow DBAL v3 Skip Doctrine DBAL on php 8 until we have a compatible version. [DomCrawler] Catch expected ValueError. Made method signatures compatible with their corresponding traits. [ErrorHandler] Apply php8 fixes from Debug component. [DomCrawler] Catch expected ValueError. [Validator] Catch expected ValueError. [VarDumper] ReflectionFunction::isDisabled() is deprecated. [BrowserKit] Raw body with custom Content-Type header [PropertyAccess] Parse php 8 TypeErrors correctly. [Intl] Fix call to ReflectionProperty::getValue() for static properties. [HttpKernel] Prevent calling method_exists() with non-string values. ...
2 parents 8af6bb4 + 48f41cb commit 663f5dd

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

OptionsResolver.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public function setDefault(string $option, $value)
185185
$reflClosure = new \ReflectionFunction($value);
186186
$params = $reflClosure->getParameters();
187187

188-
if (isset($params[0]) && null !== ($class = $params[0]->getClass()) && Options::class === $class->name) {
188+
if (isset($params[0]) && Options::class === $this->getParameterClassName($params[0])) {
189189
// Initialize the option if no previous value exists
190190
if (!isset($this->defaults[$option])) {
191191
$this->defaults[$option] = null;
@@ -206,7 +206,7 @@ public function setDefault(string $option, $value)
206206
return $this;
207207
}
208208

209-
if (isset($params[0]) && null !== ($class = $params[0]->getClass()) && self::class === $class->name && (!isset($params[1]) || (null !== ($class = $params[1]->getClass()) && Options::class === $class->name))) {
209+
if (isset($params[0]) && null !== ($type = $params[0]->getType()) && self::class === $type->getName() && (!isset($params[1]) || (null !== ($type = $params[1]->getType()) && Options::class === $type->getName()))) {
210210
// Store closure for later evaluation
211211
$this->nested[$option][] = $value;
212212
$this->defaults[$option] = [];
@@ -1280,4 +1280,13 @@ private function formatOptions(array $options): string
12801280

12811281
return implode('", "', $options);
12821282
}
1283+
1284+
private function getParameterClassName(\ReflectionParameter $parameter): ?string
1285+
{
1286+
if (!($type = $parameter->getType()) || $type->isBuiltin()) {
1287+
return null;
1288+
}
1289+
1290+
return $type->getName();
1291+
}
12831292
}

0 commit comments

Comments
 (0)