Hello! I have often run into a problem where the PHP extension doesn't recognize PHP classes and functions such as sprintf, trim, array_keys, etc. I'm not sure exactly how to fix it. I try a mix of composer install, Symfony cache clear, reload window, changing Git branches. None of it seems to work immediately. I'm not sure if the extension is still doing some kind of indexing in the background or stuck. I can close and re-open affected files to fix it sometimes, or eventually the number of Problems change and I can reload the window to fix the rest. For context in case it helps, I attach to a Docker container which has everything installed and mounted there like PHP and the project files with all of the packages.

Thanks!

AnthonyANI changed the title to Unknown Base PHP Classes and Functions.

    JakubMisek I haven't tried pre-release yet. If I can get a better feel for how often it's happening or how, I'll give it a shot and let you know if I can see that it has improved. Thanks!

      a month later

      AnthonyANI This might be caused by the incorrect setting of "php.stubs".

      Check if you don't have "php.stubs": [] (empty). You can use UI:

      You can delete "php.stubs" setting from your settings.json, to revert it to defaults (so you'll have all standard functions in IntelliSense + extensions specified in composer.json).

      16 days later

      JakubMisek Thanks for the suggestion! I checked my PHP stubs setting and it's set to defaults. To follow up on this, it only seems to happen when I first reload/open VS Code and only for the currently focused file on each tab group. If I switch to another file/tab after everything is loaded, that one is unaffected by the problem and no weird unknown class or function errors are showing. If I close the affected file/tab and let the PHP extension refresh so errors disappear then re-open the same file, the errors are gone.

        a month later

        There've been some improvements related to this issue. Does it sill happening after 1.45.15061 update?

          15 days later

          Thanks for following up! I can confirm that the issue is still present in 1.45.15061. When I start up Docker, start my containers, attach with VS Code to my PHP container and it re-opens the tabs of the files I was editing, the PHP extension starts for whichever tab happens to be in focus/active, the code analyzer doesn't recognize built-in or some imported classes like Symfony's Console Command class. I have to close the file, wait a moment for the analyzer to refresh, then re-open the file and the unknown class errors are gone. Further, on a recent occurrence of this bug, I was able to just cut something out of the file and paste it somewhere and the errors disappeared. So, modifying the file seemed to work.

            6 days later

            AnthonyANI Thank you for the details - we'll try to repro the issue. So far it all works on our machines, but I really want to figure this out.

            Write a Reply...