Open sjokkateer opened 2 years ago
This is kinda like a PHP 8.0 feature request. PHP 8.1 will have similar problems with intersection types.
I think that digging for ReflectionParameter#getType()
usages is the start of a researcher here: phpstan/psalm checks being improved would highlight these regressions caused by the language.
I see and thanks for your swift reply. Would you like me to modify this issue's format into that of a feature request, create a new issue for this matter, or are there some other steps I should take?
IMO just PR if you do any work on supporting union or intersection types 😁
What I can imagine the logic to be:
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 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::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.