Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Intelephense reports undefined symbols from libraries and extensions

Errorundefined symbol diagnostics on classes or functions that exist

Short 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.

  • Applies to VS Code, Intelephense extension, PHP 8.3
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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/project
  2. 2Match what you see, then jump to its fix

    1. 1classes from a shared library or a sibling project are undefined, project classes are fineThe library lives outside the workspace folderFix
    2. 2symbols from files such as .module or .inc are not foundThe files do not end in .phpFix
    3. 3undefined symbols for built-in or PECL extension functionsA PHP or PECL extension is missing from the stubs listFix

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 workspace

2Fix

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 Window

Confirmed by intelephense.com

Did this fix it?

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/null

2Fix

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 file

Confirmed by github.com

Did this fix it?

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 -m

2Fix

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 Window

Confirmed by intelephense.com

Did this fix it?

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

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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.