Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arrays considered as callables break autoloading #6096

Closed
Wirone opened this issue Nov 25, 2021 · 3 comments
Closed

Arrays considered as callables break autoloading #6096

Wirone opened this issue Nov 25, 2021 · 3 comments

Comments

@Wirone
Copy link
Contributor

Wirone commented Nov 25, 2021

Bug report

Since 1.2.0 we have problems with discovering symbols that were correct on 1.1.2 - it looks like it's related to MemoizingReflectionProvider::hasClass() and most probably PHPStan\Dependency\DependencyResolver::considerArrayForCallableTest().

Code snippet that reproduces the problem

ℹ️ Reproducer repo

<?php

declare(strict_types=1);

# Comment it and error disappears
$array = ['y'];

class X
{
    public function __construct()
    {
        (new \Y())->get();
    }
}

Somehow ['y'] is considered as callable and autoloading system tries to load class y. Result is cached within MemoizingReflectionProvider so when new \Y() is executed it won't work because PHPStan thinks class does not exist (provider uses lowercased names).

Additional info:

  • custom autoloader must(?) be used, we couldn't reproduce it with Composer's one
  • order of analysis is important, because if ['y'] is used after new \Y() it does not report error (in the example it's within one file, but in our repo it's in different files)

Expected output

No error like in 1.1.*

Did PHPStan help you today? Did it make you happy in any way?

I really like that @ondrejmirtes is available at Slack and I can ask him directly about our problems 🙂

@mergeable
Copy link

mergeable bot commented Nov 25, 2021

This bug report is missing a link to reproduction on phpstan.org.

It will most likely be closed after manual review.

@ondrejmirtes
Copy link
Member

This should be solved by phpstan/phpstan-src@792ce0a and phpstan/phpstan-src@b927c87.

Please try this with two-element arrays as well, thanks.

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants