Skip to content

Commit 48f41cb

Browse files
Merge branch '4.4' into 5.0
* 4.4: (27 commits) [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. Fix wrong roles comparison ...
2 parents ec9ee90 + 73e1d0f commit 48f41cb

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
@@ -180,7 +180,7 @@ public function setDefault(string $option, $value)
180180
$reflClosure = new \ReflectionFunction($value);
181181
$params = $reflClosure->getParameters();
182182

183-
if (isset($params[0]) && null !== ($class = $params[0]->getClass()) && Options::class === $class->name) {
183+
if (isset($params[0]) && Options::class === $this->getParameterClassName($params[0])) {
184184
// Initialize the option if no previous value exists
185185
if (!isset($this->defaults[$option])) {
186186
$this->defaults[$option] = null;
@@ -201,7 +201,7 @@ public function setDefault(string $option, $value)
201201
return $this;
202202
}
203203

204-
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))) {
204+
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()))) {
205205
// Store closure for later evaluation
206206
$this->nested[$option][] = $value;
207207
$this->defaults[$option] = [];
@@ -1215,4 +1215,13 @@ private function formatOptions(array $options): string
12151215

12161216
return implode('", "', $options);
12171217
}
1218+
1219+
private function getParameterClassName(\ReflectionParameter $parameter): ?string
1220+
{
1221+
if (!($type = $parameter->getType()) || $type->isBuiltin()) {
1222+
return null;
1223+
}
1224+
1225+
return $type->getName();
1226+
}
12181227
}

0 commit comments

Comments
 (0)