Skip to content

AutoloadSourceLocator should know all symbols from a file once a class is autoloaded from that file #617

Description

@ondrejmirtes

Let's say we have a file that looks like this:

class A
{
}

function b()
{
}

const C = 1;

Once the PHP runtime autoloads the class A, it also knows about b() and C which traditionally cannot be autoloaded and wouldn't be discovered otherwise.

AutoloadSourceLocator should parse the file with A before creating the Reflection and when asked about b() and C, it should report them as known.

I understand if you don't want this change - it makes the behaviour non-deterministic - if the user asks first about b(), it will not be known. But I needed this to make the static reflection's behaviour as close to runtime reflection as possible.

PoC implementation: phpstan/phpstan-src@25c7791#diff-b84fb81e70db3cdb6b4495c80b475a44

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions