Intelephense reports undefined symbols from libraries and extensions
undefined symbol diagnostics on classes or functions that existShort answer
Intelephense only knows what it indexed. Classes outside the opened workspace folder, files with a non-.php extension and symbols of PHP extensions it was not told to load are all unknown to it. Open the project root, add the extra folders to includePaths, map odd extensions in files.associations and extend the stubs list.
Fix it fast
1Find out which cause you have
Open the folder that holds composer.json as the workspace, not a single file or a parent folder, and wait for indexing to finish. Many symptoms stop here.
code /path/to/project2Match what you see, then jump to its fix
- 1
classes from a shared library or a sibling project are undefined, project classes are fineThe library lives outside the workspace folderFix - 2
symbols from files such as .module or .inc are not foundThe files do not end in .phpFix - 3
undefined symbols for built-in or PECL extension functionsA PHP or PECL extension is missing from the stubs listFix
- 1
What does the error look like?
undefined symbol diagnostics on classes or functions that exist
Cause 1 of 3
The library lives outside the workspace folder
1Check
Intelephense indexes the PHP files in the opened folder. In a multi-root workspace each folder is a separate project, and symbols do not cross over unless you link them.
# VS Code: File > Open Folder shows which folders belong to the workspace2Fix
List the extra folders in intelephense.environment.includePaths in the settings.
{
"intelephense.environment.includePaths": [
"/path/to/shared-library"
]
}3Verify
Reload the window and hover over a class from the library.
# VS Code: Developer: Reload WindowConfirmed by intelephense.com
Cause 2 of 3
The files do not end in .php
1Check
Files with a non-standard extension are not treated as PHP unless you associate them.
ls *.module *.inc 2>/dev/null2Fix
Add a glob pattern to the files.associations setting.
{
"files.associations": { "*.module": "php" }
}3Verify
The file now shows PHP highlighting, and its symbols resolve.
# VS Code status bar shows PHP for the open fileConfirmed by github.com
Cause 3 of 3
A PHP or PECL extension is missing from the stubs list
1Check
intelephense.stubs defaults to core symbols and the bundled PHP extensions. An extension outside that list has no stubs.
php -m2Fix
Add the extension's stub name to the intelephense.stubs list, keeping the default entries.
{
"intelephense.stubs": [ "<the default entries>", "<name of the extension>" ]
}3Verify
Reload the window; the diagnostic is gone.
# VS Code: Developer: Reload WindowConfirmed by intelephense.com
How do I stop it coming back?
- Open the project root, the folder with composer.json, as the workspace.
- Keep shared code in includePaths, not in random sibling folders.
- Exclude folders you do not need with intelephense.files.exclude, so indexing stays fast on large projects.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Android gets HTML instead of JSON from a PHP API
org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
The response body is not JSON.
2 causes, each with a fixBack end
Apache returns 403 when a URL contains %3F
a request like /page%3Fname=test is refused while /page?name=test works
Recent Apache httpd blocks a rewrite when the request contains an encoded question mark (%3F) and the rewritten target has a literal ?.
2 causes, each with a fixBack end
Apache returns 500 with Premature end of script headers
500 Internal Server Error
Apache ran your script, but the script printed no valid HTTP header before its output.
3 causes, each with a fixBack end
Apache returns 503 or 504 because PHP-FPM did not answer in time
Error dispatching request
Apache sent the request to PHP-FPM and gave up waiting.
3 causes, each with a fixBack end
AWS SDK for PHP cannot get credentials from the instance profile metadata server
Error retrieving credentials from the instance profile metadata server.
The SDK tries the EC2 instance metadata service when it has no valid credentials from anywhere earlier in its chain.
4 causes, each with a fixBack end
AWS SDK for PHP rejects requests: the signature is from the future
Signature not yet current: {date} is still later than {date}
AWS compares the timestamp in your signed request with its own clock.
2 causes, each with a fix