diff --git a/src/Reflection/Php/PhpParameterReflection.php b/src/Reflection/Php/PhpParameterReflection.php index 7d8f0b29ec..c134d7a1b2 100644 --- a/src/Reflection/Php/PhpParameterReflection.php +++ b/src/Reflection/Php/PhpParameterReflection.php @@ -47,8 +47,14 @@ public function getType(): Type { if ($this->type === null) { $phpDocType = $this->phpDocType; - if ($phpDocType !== null && $this->reflection->isDefaultValueAvailable() && $this->reflection->getDefaultValue() === null) { - $phpDocType = \PHPStan\Type\TypeCombinator::addNull($phpDocType); + if ($phpDocType !== null) { + try { + if ($this->reflection->isDefaultValueAvailable() && $this->reflection->getDefaultValue() === null) { + $phpDocType = \PHPStan\Type\TypeCombinator::addNull($phpDocType); + } + } catch (\Throwable $e) { + // pass + } } $this->type = TypehintHelper::decideTypeFromReflection( @@ -99,14 +105,13 @@ public function getNativeType(): Type public function getDefaultValue(): ?Type { - if ($this->reflection->isDefaultValueAvailable()) { - try { + try { + if ($this->reflection->isDefaultValueAvailable()) { $defaultValue = $this->reflection->getDefaultValue(); - } catch (\Throwable $e) { - return null; + return ConstantTypeHelper::getTypeFromValue($defaultValue); } - - return ConstantTypeHelper::getTypeFromValue($defaultValue); + } catch (\Throwable $e) { + return null; } return null;