Search code examples
phpvisual-studio-codego-to-definitionintelephense

Go To Definition for PHP extensions in VSCode


When I use Composer 'Go To Definition' works well. But it doesn't work for PHP core extensions like MySQLi. Ubuntu is my OS and I have searched for PHP files for those libraries and only find their .so files, maybe that's why I can't 'Go To Definition'.

Above are my vscode PHP definitions. Don't know if that 'Sync: Ignored' is a problem, I didn't have path for PHP binary setted in settings.json but I tried to add it and it didn't make difference.

How solve this?

My vscode PHP definitions

{
"editor.detectIndentation": false,
"C_Cpp.updateChannel": "Insiders",
"riot.base": "/home/fe/RIOT",
"riot.board": "esp8266-esp-12x",
"[lisp]": {
    "editor.tabSize": 2
},
"[html]": {
    "editor.tabSize": 2
},
"phpserver.browser": "firefox",
"typescript.disableAutomaticTypeAcquisition": true,
"intelephense.stubs": [
    "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",
    "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",
    "mysqli"
],
"php.validate.executablePath": "/usr/bin/php"
}

Solution

  • You can't go to the definition of standard functions. PHP doesn't offer such functionality.

    Intelephense uses stubs from PHPStorm to specify the syntax and PHPDoc comments, but going to the definition of these files would be pointless. Everything you need is shown to you in the popover. For this reason, going to the definition in the stub files is blocked.

    PHP core extensions are compiled. PHP is an interpreted language but the executable is compiled C source code. PHP core extensions are written in C, not in PHP. There's no reason to go to the definition in C source code even if such functionality would be available in VS Code.