Skip to content

The ReflectionClassConstructorThrowTypeExtension can be improved to support object. #5195

@VincentLanglet

Description

@VincentLanglet

Feature request

The ReflectionClassConstructorThrowTypeExtension only check for constantString

So

new \ReflectionClass(Foo::class);

is not throwing an exception.

But

new \ReflectionClass(new Foo());

does.

The Extension is doing

foreach (TypeUtils::getConstantStrings($valueType) as $constantString) {
     if (!$this->reflectionProvider->hasClass($constantString->getValue())) {
          return $methodReflection->getThrowType();
     }

     $valueType = TypeCombinator::remove($valueType, $constantString);
}

checking for Bar::class|Foo::class|...

What would be the equivalent way to check for Bar|Foo|... @ondrejmirtes ? I can do the PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions