Bug Report
Summary
When trying to create an object that depends on a union type in its constructor, a call to Injector::create() results in an error.
Current behavior
The Injector::class forwards the resolveParameters() call to the DependencyResolver::resolveParameters() method, which, at L#280 makes a call to Parameter::getType(). Within this method, a call is made to the underlying object's ReflectionParameter::getType() method is made. The returned object by getType() is a ReflectionUnionType::class, which has no method getName() defined, and hence, it crashes the program due to L#63.
The error message:
Error: Call to undefined method ReflectionUnionType::getName()
How to reproduce
Settings:
PHP 8.0.19 (cli)
Class definition:
class Foo
{
public function __construct(private string|Stringable $s)
{
}
public function getS(): string|Stringable
{
return $this->s;
}
}
Test case:
public function testCreateClassWithUnionTypeParameterAsConstructorArgument(): void
{
$injector = new Injector();
$s = 'Hello, World';
$foo = $injector->create(Foo::class, ['s' => $s]);
$actualS = $foo->getS();
$this->assertEquals($s, $actualS);
}
Expected behavior
An instance of Foo::class constructed with the property $s set to the string value 'Hello, World'.
PS
I am sorry if this is not considered a bug, but I did not know where to otherwise post this matter. Please let me know what you think of the above stated.
Bug Report
Summary
When trying to create an object that depends on a union type in its constructor, a call to
Injector::create()results in an error.Current behavior
The
Injector::classforwards theresolveParameters()call to theDependencyResolver::resolveParameters()method, which, at L#280 makes a call to Parameter::getType(). Within this method, a call is made to the underlying object'sReflectionParameter::getType()method is made. The returned object bygetType()is a ReflectionUnionType::class, which has no methodgetName()defined, and hence, it crashes the program due to L#63.The error message:
Error: Call to undefined method ReflectionUnionType::getName()How to reproduce
Settings:
PHP 8.0.19 (cli)Class definition:
Test case:
Expected behavior
An instance of
Foo::classconstructed with the property$sset to the string value'Hello, World'.PS
I am sorry if this is not considered a bug, but I did not know where to otherwise post this matter. Please let me know what you think of the above stated.