phpstan: Class not found - case-insensitive caching of case-sensitive results

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.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 22 (11 by maintainers)

Most upvoted comments

We could make it do that only if the ConstantStringType comes from ::class