[php-src] Issue #14085: Extend Reflection a bit more to expose import statements

From: Date: Tue, 30 Apr 2024 14:08:56 +0000
Subject: [php-src] Issue #14085: Extend Reflection a bit more to expose import statements
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-246841@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/14085 Author: Korbeil ### Description 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 the as keyword: ```php use App\Command\Foo as Command; /** @var Command */ $command = my_command(); ``` Another example, you have two classes with the same name but in different namespaces: App\Foo and App\Command\Foo ```php use App\Command\Foo; /** @var Foo */ $command = my_command(); ``` 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.

« previous php.bugs (#246841) next »