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

Bug? Callmap doesnt work for extensions if the extension is not installed #10307

Open
mhsdesign opened this issue Oct 21, 2023 · 3 comments
Open

Comments

@mhsdesign
Copy link

I was just trying to run my linting locally and the fact that i have certain extensions not installed made it very hard.

Docblock-defined class, interface or enum named Memcache does not exist
Class, interface or enum named Memcached does not exist
Docblock-defined class, interface or enum named Redis does not exist
Docblock-defined class, interface or enum named APCUIterator does not exist

In my case i rely on APCUIterator Memcache Memcached and Redis.
(My usecase is like the one another user had (unanswered): https://stackoverflow.com/questions/73703563/psalm-how-to-deal-with-optional-classes)

So after investigating a bit into the matter i found that redis as well as apcu seem to be a special cases as there are literally extension_loaded checks in place which enable the subs:

if (extension_loaded('redis')) {

But for memcache i couldnt find such logic, only that the CallMap correctly specifies the class:

https://github.com/vimeo/psalm/blob/4.x/dictionaries/CallMap.php#L7349

I played a little around with the code base but haven been able to find the location which determines to only load this callmap if the extension is installed.

It seems that eventually extension support will get better in psalm 5 #7107 but i assume - as i wasnt able to specify memcache as enableExtensions in 5.x - the same problem exists there for now as well, until the extensions are migrated to stub files?

Related #7982 which also highlighted:

It's still unclear to me why the CallMap doesn't work in this case, but my personal goal is to remove extensions from the CallMap anyway 🤷

Tested with vimeo/psalm: 4.30.0

@psalm-github-bot
Copy link

Hey @mhsdesign, can you reproduce the issue on https://psalm.dev ?

@robchett
Copy link
Contributor

I don't believe that Psalm 4 or 5 have stub files for the memcache/memcached classes so it relies on reflection to populate them.

You could add your own stub file to your project to give Psalm the information it needs when the extension is not installed.
If you also want to contribute that back to Psalm I'm sure it would be welcome, as it can then be used for anyone requiring ext-memcache(d) in their composer.json.

@mhsdesign
Copy link
Author

Yes there are no stubs. But im wondering what the callmap file is for, which declares the memcache extension's classes correctly, and why it doesnt seem to work? Maybe its obsolete and reflection is always used?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants