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

Instantiated class XXX not found when using class_alias() in bootstrap #6187

Closed
wim-web opened this issue Dec 10, 2021 · 3 comments
Closed

Comments

@wim-web
Copy link

wim-web commented Dec 10, 2021

Bug report

First, create an alias named with class_alias through spl_autoload_register in bootstrap.
If there is an array with a different case from the alias before the point where the alias is used, an error will occur.(ex: Instantiated class PiyoAlias not found.)

Probably the fastest way to understand is to look at the commits in the link below.

I noticed this problem when I was using laravel.
Using laravel's facade feature, you may have this problem.

Code snippet that reproduces the problem

Paste the link to the repository because bootstrap is required

https://github.com/wim-web/phpstan-src/commit/aa19f495541e802c90b32a07ed9329ecaf72fdf9

Expected output

No Errors

Anticipated causes

da34d3f1d642d71d5a5130d371bb243c65b0b195

error has occurred from above commit.

The isClassString method is called in the callerArrayForCallableTest method of the DependencyResolver class.
The isClassString calls MemoizingReflectionProvider's hasClass and stores the result with strtolower($className) as a key.
class_alias is case-sensitive, so no class will be found and false will be returned.
trying to new with an alias name, the result will be "Instantiated class PiyoAlias not found" because it is cached and not found.

i would like to fix it. but, code is complex for me and i don't have good idea.

@mergeable
Copy link

mergeable bot commented Dec 10, 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

Hi, this should improve the situation: phpstan/phpstan-src@b927c87

Please test phpstan/phpstan dev-master, 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 11, 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