vscode-intelephense
vscode-intelephense copied to clipboard
Indexing problem - `Undefined type` errors after using something from composer (without reloading vscode)
To Reproduce
- Init empty project
- Create file e.g.
test.php
- Run
composer require phpmailer/phpmailer
- Paste PHPMailer simple example into
test.php
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
// Load Composer's autoloader
require 'vendor/autoload.php';
// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'smtp1.example.com'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail->Port = 587; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail->setFrom('[email protected]', 'Mailer');
$mail->addAddress('[email protected]', 'Joe User'); // Add a recipient
$mail->addAddress('[email protected]'); // Name is optional
$mail->addReplyTo('[email protected]', 'Information');
$mail->addCC('[email protected]');
$mail->addBCC('[email protected]');
// Attachments
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
Expected behavior This error should disappear because the namespaces are correct I need to reload VSCode so that these errors disappear
Screenshot without reloading
Screenshot after reloading
Platform and version
Version: 1.45.1 (system setup)
Commit: 5763d909d5f12fe19f215cbfdd29a91c0fa9208a
Date: 2020-05-14T08:27:35.169Z
Electron: 7.2.4
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Windows_NT x64 10.0.18363
Do you need to reload or just close/ reopen file or edit it for them to disappear?
I need reload Close / reopen file or edit doesn't help
Undefined type 'PHPUnit\Framework\TestCase'.intelephense(1009) even after reload
edit: 1.4.1 seems to be indexing it fine
I tested with 1.4.1. The problem still exists. Nothing has changed
I have similar problems with it, sometimes it works sometimes it doesn't.
I have no idea what that might be. I have tried restarting vs code, closing the file, making changes, even changing the php version.
I've just run across this exact same problem for the first time. Previous composer updates have been fine but this time I suddenly got Undefined Type errors for a vendor package that previously worked fine.
Same here. Not sure if it matters, in my case "vendor" folder is below the workspace.
Dunno if the problem is related but I'm facing the same issue even with something as simple as a FileException
catch.
Still present in 1.7.1.
My error gone after restart
I just realised that I have the same issue in v 1.63 of vs code, v1.80 of the extension
I recently switch from phpstorm to vs code and did not really managed to figure out if this behaviour was vs code of this plugin, buy two day ago I reinstalled my mac and now I only have this extension in VSCode.
I'm using Laravel and the ide-helper, not sure if that an issue or an benefit
The issue disappears after restart of vscode, but it is not convenient to restart several times
Same problem.
VS Code: 1.63.0
PHP Intelephense v1.8.0
Restarting doesn't solve unfortunately.
I've encountered the same problem. What worked for in VS Code me was this:

So open the command palette and make intelephense re-index the workspace.
Thanks @nxcco this helped. and make sense in my case since I updated the composer content while vsCOde was opened... Maybe a trigger missing to tell intelephese about external update of the source base?
There should be a filewatcher that detects the addition and removal of files. Does anyone have vendor files excluded in the files.watcherExclude
setting?
Closing VS Code and Re-Opening it will solve this issue.
There should be a filewatcher that detects the addition and removal of files. Does anyone have vendor files excluded in the
files.watcherExclude
setting?
I have the default setting and have never changed it:
Closing VS Code and Re-Opening it will solve this issue.
It doesn't fix anything, it's a workaround (which is inconvenient anyway)
I found that adding "vendor" to files.exclude in .vscode/settings.json would prevent type acquisition from Composer packages. Also, make sure to restart VSCode every time you do something to test whether it fixes the problem - you can't trust VSCode to reload types on the fly it seems.
For me I installed some PHP Extensions like PHP and PHP Intellisense, Extension Pack, etc, and restarted VS code, the error was gone
tracking composer issue in #2213