-
-
Notifications
You must be signed in to change notification settings - Fork 96
Getting Started
You will get more out of Intelephense if you provide type information in your code. This can be via coded type declarations or PHPDoc type annotations. Where both have been provided, PHPDoc type annotations are given precedence as they can provide richer type information.
<?php
/**
* @param string $param Parameter type annotation
* @return string[] Return type annotation providing richer information on the array type
**/
function myFunction(string $param): array {} // <- type declarations for $param and function return
Providing type information will result in a better experience.
- Language intelligence (completion suggestions, go to definition, diagnostics, etc) is improved when Intelephense knows the type of a variable.
- Performance will be improved as Intelephense will not have to scan function implementations in order to infer return types.
For Intelephense to work effectively it must have access to the definitions of the symbols used in your code. It does this by scanning the php files found in the workspace. Intelephense currently has a file limitation of 262143 PHP files. If your workspace has more than this then you should consider opening a smaller workspace or exclude unnecessary files via the intelephense.files.exclude
setting. Opening a single file rather than a workspace folder will result in many undefined symbol diagnostics if that file is part of a larger project.
Sometimes PHP files may have a non standard extension. It is important to associate these extensions with PHP using the intelephense.files.associations
configuration option.
{
"intelephense.files.associations": ["*.php", "*.phtml", "*.inc", "*.module"]
}
You may have large files in your workspace that by default Intelephense will skip (> 1MB). You can configure the maximum file size with the intelephense.files.maxSize
option.
{
"intelephense.files.maxSize": 5000000
}
There may be files you do not want to indexed by Intelephense. It is important in large projects to exclude unnecessary files to avoid polluting suggestion lists and degrading performance.
{
"intelephense.files.exclude": [
"**/.git/**",
"**/.svn/**",
"**/.hg/**",
"**/CVS/**",
"**/.DS_Store/**",
"**/node_modules/**",
"**/bower_components/**",
"**/vendor/**/{Tests,tests}/**",
"**/.history/**",
"**/vendor/**/vendor/**"
]
}
Sometimes symbol definitions are not in your workspace but are core PHP symbols or defined in an extension. For this reason Intelephense includes stub definitions for many of these. Extensions that are bundled with PHP are enabled by default. You can configure what other symbols are available in your environment with the intelephense.stubs
option.
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"
}
Other configuration settings that allow you to further define the PHP environment include:
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 theinclude_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 andgreater supported.",
"scope": "window"
}
intelephense.environment.shortOpenTag
{
"type": "boolean",
"default": false,
"description": "When enabled '<?' will be parsed as a PHP open tag. Defaults tofalse.",
"scope": "window"
}
Support the development of this extension and access additional features by purchasing a licence at https://intelephense.com