I have some helper functions that I use everywhere in a CakePHP 2 application. They are underlined with red and reported as 'undefined functions' in the console. I know I can just ignore the errors, but I would like to have it working properly going forward, especially if I can manage to get alt-click working with it for models.
In my VS Code settings.json
, I have the following:
"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", "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", "wordpress",
"./Config/core.php"
],
It's my understanding that it is allowed to import custom .php files as stubs so that Intelephense recognizes them. However, no path that I enter will work. I have tried everything I can think of:
How can I get Intelephense to recognize core.php, which essentially just holds a bunch of settings and some helper functions defined as, for example:
// just an alias for json decode
function jdec($json) {
return json_decode($json, 1, 512, JSON_INVALID_UTF8_IGNORE);
}
Note: I am sure my difficulty with Intelephense is not strictly related to the CakePHP 2 framework.
I think you need to add CakePHP 2 location path to intelephense.environment.includePaths
setting.
Here's an example of my workspace config for similar situation. I have the libraries I include outside of my workspace, so I specify paths to those like this:
"intelephense.environment.includePaths": [
"/path/to/lib1",
"/path/to/lib2"
]
After this, all the functions from included libraries are properly indexed by Intelephense and no longer marked as undefined
.