Visual Studio Code users should install the Intelephense extension from within the extensions view or download from the marketplace.
-
Disable the built-in VSCode PHP Language Features.
- Go to
Extensions
. - Search for
@builtin php
- Disable
PHP Language Features
. LeavePHP Language Basics
enabled for syntax highlighting.
Note that other (3rd party) PHP extensions which provide similar functionality should also be disabled for best results.
- Go to
-
Add glob patterns for non standard php file extensions to the
files.associations
setting.For example:
"files.associations": { "*.module": "php" }
. -
Optionally purchase and enter your licence key by opening the command pallete --
ctrl + shift + p
-- and searching forEnter licence key
.
Further configuration options are available in the intelephense
section of settings.
npm i intelephense -g
Intelephense needs an LSP compliant client to communicate with and integrate features into the editor. A list of editors and clients that support the LSP can be found at https://microsoft.github.io/language-server-protocol/implementors/tools/.
Please follow the setup guide of the relevant tool. The Information below may help in configuring the client.
intelephense {transport}
Where {transport}
is one of:
--node-ipc
--stdio
--socket={number}
--pipe={string}
interface InitialisationOptions {
//Optional absolute path to storage dir. Defaults to os.tmpdir().
storagePath?: string;
//Optional absolute path to a global storage dir. Defaults to os.homedir().
globalStoragePath?: string;
//Optional licence key or absolute path to a text file containing the licence key.
//{os.homedir()}/intelephense/licence.txt will also be checked by
//default if initializationOptions are not exposed by client.
licenceKey?: string;
//Optional flag to clear server state.
//State can also be cleared by deleting {storagePath}/intelephense
clearCache?: boolean;
}
Server capabilities JSON returned from `initialize` request.
{
textDocumentSync: TextDocumentSyncKind.Incremental,
documentSymbolProvider: true,
workspaceSymbolProvider: true,
completionProvider: {
triggerCharacters: [
//php
'$', '>', ':', '\\', '/',
//phpdoc
'*',
// html/js
'.', '<'
],
resolveProvider: true
},
signatureHelpProvider: {
triggerCharacters: ['(', ',']
},
definitionProvider: true,
referencesProvider: true,
hoverProvider: true,
documentFormattingProvider: true, //Dynamic registration if available.
documentRangeFormattingProvider: true, //Dynamic registration if available.
documentHighlightProvider: true,
workspace: {
workspaceFolders: {
supported: true,
changeNotifications: true
}
},
foldingRangeProvider: true, //With licence key only.
implementationProvider: true, //With licence key only.
declarationProvider: true, //With licence key only.
renameProvider: { //With licence key only.
prepareProvider: true
},
typeDefinitionProvider: true, //With licence key only.
selectionRangeProvider: true //With licence key only.
}
JSON schema for `workspace/configuration` request data
{
"intelephense.compatibility.correctForBaseClassStaticUnionTypes": {
"type": "boolean",
"default": true,
"description": "Resolves `BaseClass|static` union types to `static` instead of `BaseClass`.",
"scope": "window"
},
"intelephense.compatibility.correctForArrayAccessArrayAndTraversableArrayUnionTypes": {
"type": "boolean",
"default": true,
"description": "Resolves `ArrayAccess` and `Traversable` implementations that are unioned with a typed array to generic syntax. eg `ArrayAccessOrTraversable|ElementType[]` => `ArrayAccessOrTraversable<mixed, ElementType>`.",
"scope": "window"
},
"intelephense.files.maxSize": {
"type": "number",
"default": 1000000,
"description": "Maximum file size in bytes.",
"scope": "window"
},
"intelephense.files.associations": {
"type": "array",
"default": [
"*.php",
"*.phtml"
],
"description": "Configure glob patterns to make files available for language server features. Inherits from files.associations.",
"scope": "window"
},
"intelephense.files.exclude": {
"type": "array",
"items": {
"type": "string"
},
"default": [
"**/.git/**",
"**/.svn/**",
"**/.hg/**",
"**/CVS/**",
"**/.DS_Store/**",
"**/node_modules/**",
"**/bower_components/**",
"**/vendor/**/{Tests,tests}/**",
"**/.history/**",
"**/vendor/**/vendor/**"
],
"description": "Configure glob patterns to exclude certain files and folders from all language server features. Inherits from files.exclude.",
"scope": "resource"
},
"intelephense.stubs": {
"type": "array",
"items": {
"type": "string",
"enum": [
"amqp",
"apache",
"apcu",
"bcmath",
"blackfire",
"bz2",
"calendar",
"cassandra",
"com_dotnet",
"Core",
"couchbase",
"crypto",
"ctype",
"cubrid",
"curl",
"date",
"dba",
"decimal",
"dom",
"ds",
"enchant",
"Ev",
"event",
"exif",
"fann",
"FFI",
"ffmpeg",
"fileinfo",
"filter",
"fpm",
"ftp",
"gd",
"gearman",
"geoip",
"geos",
"gettext",
"gmagick",
"gmp",
"gnupg",
"grpc",
"hash",
"http",
"ibm_db2",
"iconv",
"igbinary",
"imagick",
"imap",
"inotify",
"interbase",
"intl",
"json",
"judy",
"ldap",
"leveldb",
"libevent",
"libsodium",
"libxml",
"lua",
"lzf",
"mailparse",
"mapscript",
"mbstring",
"mcrypt",
"memcache",
"memcached",
"meminfo",
"meta",
"ming",
"mongo",
"mongodb",
"mosquitto-php",
"mqseries",
"msgpack",
"mssql",
"mysql",
"mysql_xdevapi",
"mysqli",
"ncurses",
"newrelic",
"oauth",
"oci8",
"odbc",
"openssl",
"parallel",
"Parle",
"pcntl",
"pcov",
"pcre",
"pdflib",
"PDO",
"pdo_ibm",
"pdo_mysql",
"pdo_pgsql",
"pdo_sqlite",
"pgsql",
"Phar",
"phpdbg",
"posix",
"pspell",
"pthreads",
"radius",
"rar",
"rdkafka",
"readline",
"recode",
"redis",
"Reflection",
"regex",
"rpminfo",
"rrd",
"SaxonC",
"session",
"shmop",
"SimpleXML",
"snmp",
"soap",
"sockets",
"sodium",
"solr",
"SPL",
"SplType",
"SQLite",
"sqlite3",
"sqlsrv",
"ssh2",
"standard",
"stats",
"stomp",
"suhosin",
"superglobals",
"svn",
"sybase",
"sync",
"sysvmsg",
"sysvsem",
"sysvshm",
"tidy",
"tokenizer",
"uopz",
"uv",
"v8js",
"wddx",
"win32service",
"winbinder",
"wincache",
"wordpress",
"xcache",
"xdebug",
"xhprof",
"xml",
"xmlreader",
"xmlrpc",
"xmlwriter",
"xsl",
"xxtea",
"yaf",
"yaml",
"yar",
"zend",
"Zend OPcache",
"ZendCache",
"ZendDebugger",
"ZendUtils",
"zip",
"zlib",
"zmq",
"zookeeper"
]
},
"default": [
"apache",
"bcmath",
"bz2",
"calendar",
"com_dotnet",
"Core",
"ctype",
"curl",
"date",
"dba",
"dom",
"enchant",
"exif",
"FFI",
"fileinfo",
"filter",
"fpm",
"ftp",
"gd",
"gettext",
"gmp",
"hash",
"iconv",
"imap",
"intl",
"json",
"ldap",
"libxml",
"mbstring",
"meta",
"mysqli",
"oci8",
"odbc",
"openssl",
"pcntl",
"pcre",
"PDO",
"pdo_ibm",
"pdo_mysql",
"pdo_pgsql",
"pdo_sqlite",
"pgsql",
"Phar",
"posix",
"pspell",
"readline",
"Reflection",
"session",
"shmop",
"SimpleXML",
"snmp",
"soap",
"sockets",
"sodium",
"SPL",
"sqlite3",
"standard",
"superglobals",
"sysvmsg",
"sysvsem",
"sysvshm",
"tidy",
"tokenizer",
"xml",
"xmlreader",
"xmlrpc",
"xmlwriter",
"xsl",
"Zend OPcache",
"zip",
"zlib"
],
"description": "Configure stub files for built in symbols and common extensions. The default setting includes PHP core and all bundled extensions.",
"scope": "window"
},
"intelephense.completion.insertUseDeclaration": {
"type": "boolean",
"default": true,
"description": "Use declarations will be automatically inserted for namespaced classes, traits, interfaces, functions, and constants.",
"scope": "window"
},
"intelephense.completion.fullyQualifyGlobalConstantsAndFunctions": {
"type": "boolean",
"default": false,
"description": "Global namespace constants and functions will be fully qualified (prefixed with a backslash).",
"scope": "window"
},
"intelephense.completion.triggerParameterHints": {
"type": "boolean",
"default": true,
"description": "Method and function completions will include parentheses and trigger parameter hints.",
"scope": "window"
},
"intelephense.completion.maxItems": {
"type": "number",
"default": 100,
"description": "The maximum number of completion items returned per request.",
"scope": "window"
},
"intelephense.format.enable": {
"type": "boolean",
"default": true,
"description": "Enables formatting.",
"scope": "window"
},
"intelephense.format.braces": {
"type": "string",
"default": "psr12",
"enum": [
"psr12",
"allman",
"k&r"
],
"enumDescriptions": [
"PHP-FIG PSR-2 and PSR-12 style. A mix of Allman and K&R",
"Allman. Opening brace on the next line.",
"K&R (1TBS). Opening brace on the same line."
],
"description": "Controls formatting style of braces",
"scope": "window"
},
"intelephense.environment.documentRoot": {
"type": "string",
"description": "The directory of the entry point to the application (index.php). Defaults to the first workspace folder. Used for resolving script inclusion.",
"scope": "window"
},
"intelephense.environment.includePaths": {
"type": "array",
"items": {
"type": "string"
},
"description": "The include paths (as individual path items) as defined in the include_path ini setting. Used for resolving script inclusion.",
"scope": "window"
},
"intelephense.environment.phpVersion": {
"type": "string",
"default": "7.4.0",
"description": "A semver compatible string that represents the target PHP version. Used for providing version appropriate suggestions and diagnostics. PHP 5.3.0 and greater supported.",
"scope": "window"
},
"intelephense.environment.shortOpenTag": {
"type": "boolean",
"default": false,
"description": "When enabled '<?' will be parsed as a PHP open tag. Defaults to false.",
"scope": "window"
},
"intelephense.diagnostics.enable": {
"type": "boolean",
"default": true,
"description": "Enables diagnostics.",
"scope": "window"
},
"intelephense.diagnostics.run": {
"type": "string",
"default": "onType",
"enum": [
"onType",
"onSave"
],
"enumDescriptions": [
"Diagnostics will run as changes are made to the document.",
"Diagnostics will run when the document is saved."
],
"description": "Controls when diagnostics are run.",
"scope": "window"
},
"intelephense.diagnostics.embeddedLanguages": {
"type": "boolean",
"default": true,
"description": "Enables diagnostics in embedded languages.",
"scope": "window"
},
"intelephense.diagnostics.undefinedSymbols": {
"type": "boolean",
"default": true,
"description": "DEPRECATED. Use the setting for each symbol category.",
"scope": "window"
},
"intelephense.diagnostics.undefinedVariables": {
"type": "boolean",
"default": true,
"description": "Enables undefined variable diagnostics.",
"scope": "window"
},
"intelephense.diagnostics.undefinedTypes": {
"type": "boolean",
"default": true,
"description": "Enables undefined class, interface and trait diagnostics.",
"scope": "window"
},
"intelephense.diagnostics.undefinedFunctions": {
"type": "boolean",
"default": true,
"description": "Enables undefined function diagnostics.",
"scope": "window"
},
"intelephense.diagnostics.undefinedConstants": {
"type": "boolean",
"default": true,
"description": "Enables undefined constant diagnostics.",
"scope": "window"
},
"intelephense.diagnostics.undefinedClassConstants": {
"type": "boolean",
"default": true,
"description": "Enables undefined class constant diagnostics.",
"scope": "window"
},
"intelephense.diagnostics.undefinedMethods": {
"type": "boolean",
"default": true,
"description": "Enables undefined method diagnostics.",
"scope": "window"
},
"intelephense.diagnostics.undefinedProperties": {
"type": "boolean",
"default": true,
"description": "Enables undefined static property diagnostics.",
"scope": "window"
},
"intelephense.diagnostics.unusedSymbols": {
"type": "boolean",
"default": true,
"description": "Enables unused variable, private member, and import diagnostics.",
"scope": "window"
},
"intelephense.diagnostics.unexpectedTokens": {
"type": "boolean",
"default": true,
"description": "Enables unexpected token diagnostics.",
"scope": "window"
},
"intelephense.diagnostics.duplicateSymbols": {
"type": "boolean",
"default": true,
"description": "Enables duplicate symbol diagnostics.",
"scope": "window"
},
"intelephense.diagnostics.argumentCount": {
"type": "boolean",
"default": true,
"description": "Enables argument count diagnostics.",
"scope": "window"
},
"intelephense.diagnostics.typeErrors": {
"type": "boolean",
"default": true,
"description": "Enables diagnostics on type compatibility of arguments, property assignments, and return statements where types have been declared.",
"scope": "window"
},
"intelephense.diagnostics.deprecated": {
"type": "boolean",
"default": true,
"description": "Enables deprecated diagnostics.",
"scope": "window"
},
"intelephense.diagnostics.languageConstraints": {
"type": "boolean",
"default": true,
"description": "Enables reporting of various language constraint errors.",
"scope": "window"
},
"intelephense.diagnostics.implementationErrors": {
"type": "boolean",
"default": true,
"description": "Enables reporting of problems associated with method and class implementations. For example, unimplemented methods or method signature incompatibilities.",
"scope": "window"
},
"intelephense.runtime": {
"type": "string",
"description": "Path to a Node.js executable. Use this if you wish to use a different version of Node.js. Defaults to Node.js shipped with VSCode.",
"scope": "machine"
},
"intelephense.maxMemory": {
"type": "number",
"description": "Maximum memory (in MB) that the server should use. On some systems this may only have effect when runtime has been set. Minimum 256.",
"scope": "window"
},
"intelephense.licenceKey": {
"type": "string",
"description": "DEPRECATED. Don't use this. Go to command palette and search for enter licence key.",
"scope": "application"
},
"intelephense.telemetry.enabled": {
"type": "boolean",
"description": "Anonymous usage and crash data will be sent to Azure Application Insights. Inherits from telemetry.enableTelemetry.",
"scope": "window",
"default": null
},
"intelephense.rename.exclude": {
"type": "array",
"items": {
"type": "string"
},
"default": [
"**/vendor/**"
],
"description": "Glob patterns matching files and folders that should be excluded when renaming symbols. Rename operation will fail if the symbol definition is found in the excluded files/folders.",
"scope": "resource"
},
"intelephense.references.exclude": {
"type": "array",
"items": {
"type": "string"
},
"default": [
"**/vendor/**"
],
"description": "Glob patterns matching files and folders that should be excluded from references search.",
"scope": "resource"
},
"intelephense.phpdoc.returnVoid": {
"type": "boolean",
"default": true,
"description": "Adds `@return void` to auto generated phpdoc for definitions that do not return a value.",
"scope": "window"
},
"intelephense.phpdoc.textFormat": {
"type": "string",
"enum": [
"snippet",
"text"
],
"default": "snippet",
"enumDescriptions": [
"Auto generated phpdoc is returned in snippet format. Templates are partially resolved by evaluating phpdoc specific variables only.",
"Auto generated phpdoc is returned as plain text. Templates are resolved completely by the server."
],
"scope": "window"
},
"intelephense.phpdoc.classTemplate": {
"type": "object",
"properties": {
"summary": {
"type": "string",
"description": "A snippet string representing a phpdoc summary."
},
"description": {
"type": "string",
"description": "A snippet string representing a phpdoc description."
},
"tags": {
"type": "array",
"items": {
"type": "string"
},
"description": "An array of snippet strings representing phpdoc tags."
}
},
"default": {
"summary": "$1",
"tags": [
"@package ${1:$SYMBOL_NAMESPACE}"
]
},
"description": "An object that describes the format of generated class/interface/trait phpdoc. The following snippet variables are available: SYMBOL_NAME; SYMBOL_KIND; SYMBOL_TYPE; SYMBOL_NAMESPACE.",
"scope": "window"
},
"intelephense.phpdoc.propertyTemplate": {
"type": "object",
"properties": {
"summary": {
"type": "string",
"description": "A snippet string representing a phpdoc summary."
},
"description": {
"type": "string",
"description": "A snippet string representing a phpdoc description."
},
"tags": {
"type": "array",
"items": {
"type": "string"
},
"description": "An array of snippet strings representing phpdoc tags."
}
},
"default": {
"summary": "$1",
"tags": [
"@var ${1:$SYMBOL_TYPE}"
]
},
"description": "An object that describes the format of generated property phpdoc. The following snippet variables are available: SYMBOL_NAME; SYMBOL_KIND; SYMBOL_TYPE; SYMBOL_NAMESPACE.",
"scope": "window"
},
"intelephense.phpdoc.functionTemplate": {
"type": "object",
"properties": {
"summary": {
"type": "string",
"description": "A snippet string representing a phpdoc summary."
},
"description": {
"type": "string",
"description": "A snippet string representing a phpdoc description."
},
"tags": {
"type": "array",
"items": {
"type": "string"
},
"description": "An array of snippet strings representing phpdoc tags."
}
},
"default": {
"summary": "$1",
"tags": [
"@param ${1:$SYMBOL_TYPE} $SYMBOL_NAME $2",
"@return ${1:$SYMBOL_TYPE} $2",
"@throws ${1:$SYMBOL_TYPE} $2"
]
},
"description": "An object that describes the format of generated function/method phpdoc. The following snippet variables are available: SYMBOL_NAME; SYMBOL_KIND; SYMBOL_TYPE; SYMBOL_NAMESPACE.",
"scope": "window"
},
"intelephense.phpdoc.useFullyQualifiedNames": {
"type": "boolean",
"default": false,
"description": "Fully qualified names will be used for types when true. When false short type names will be used and imported where appropriate. Overrides intelephense.completion.insertUseDeclaration.",
"scope": "window"
}
}