Skip to content

Class not found - case-insensitive caching of case-sensitive results #3428

@rainbow-alex

Description

@rainbow-alex

Bug report

Memoization in MemoizingReflectionProvider lowercases the classname before using it as the cache key. If you reference the class with an incorrect case, and it fails to be autoloaded, the provider caches it as 'not found'. If it is then referenced with the correct casing the provider will not try to find it and report it as not found.

https://github.com/phpstan/phpstan-src/blob/7738778a6dafdc0685d4b0477058a8d3ab3af065/src/Reflection/BetterReflection/Reflector/MemoizingClassReflector.php#L23

Code snippet that reproduces the problem

Assuming a case-sensitive autoloader that can find SomeClass but not someclass:

<?php
new someclass;
new SomeClass;

Output:

Instantiated class company not found.
Instantiated class Company not found.

Expected output

Instantiated class someclass not found.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions