You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Nowadays there is a limit when trying to resolve a type from a phpDoc in PHP, you'll need to get a "context" for the file where the type as been written. Let's make an exemple with a use import combined with the as keyword:
Considering both theses example, we require to parse the whole file to check for use import statements so we can have context for the phpDoc types within this file.
To solve this issue with Reflection, it would require:
ReflectionFile an object that describe the content of a file: a list of ReflectionImport and any other stuff within that file (ReflectionClass ...)
ReflectionImport an object that describe a use statement with a linked ReflectionClass and a local alias when required
I chosed to not use the keyword use within Reflection here because I think it's too much missleading and import has more meaning in that context.
The text was updated successfully, but these errors were encountered:
Hi @Korbeil! This information is not readily available at runtime. The use list is only used at compile-time to resolve the symbols used in the current file. Given that we now have attributes, which do use the use list for resolving symbols, I'm not sure anybody is interested in extending doc blocks further. There are existing solutions to this problem. Maybe you could try https://github.com/phpstan/phpdoc-parser. Disclaimer though, I do not know exactly how this library works and whether it can solve your exact use-case.
Hey,
Nowadays there is a limit when trying to resolve a type from a phpDoc in PHP, you'll need to get a "context" for the file where the type as been written. Let's make an exemple with a
use
import combined with theas
keyword:Another example, you have two classes with the same name but in different namespaces:
App\Foo
andApp\Command\Foo
Considering both theses example, we require to parse the whole file to check for
use
import statements so we can have context for the phpDoc types within this file.To solve this issue with Reflection, it would require:
ReflectionFile
an object that describe the content of a file: a list ofReflectionImport
and any other stuff within that file (ReflectionClass
...)ReflectionImport
an object that describe a use statement with a linkedReflectionClass
and a local alias when requiredI chosed to not use the keyword
use
within Reflection here because I think it's too much missleading andimport
has more meaning in that context.The text was updated successfully, but these errors were encountered: