26

I'm using Visual Studio Code to develop in PHP, and I've been having some trouble getting Code to provide the proper intellisense results. For example, this newly created Codeception unit test:

<?php

class MyTest extends \Codeception\Test\Unit
{
    /**
     * @var \UnitTester
     */
    protected $tester;

    protected function _before()
    {
    }

    protected function _after()
    {
    }

    // tests
    public function testSomeFeature()
    {
        $this->assertFalse(false);
    }
}

When I type $this-> I expect to see assertFalse, assertTrue, and all the other methods provided by \Codeception\Test\Unit. But what I get is basically whatever items exist within the current file and that's it.

incomplete intellisense

What can I do to get all the methods from the Unit class to show up? I already have the PHP IntelliSense extension installed, v2.3.4.

4
  • 5
    Visual Studio Code does not include a language server for PHP by default. You need to install a third-party extension. I'd recommend PHP Intelephense. Commented Aug 26, 2018 at 12:49
  • @ÁlvaroGonzález thank you for the suggestion. Would you recommend removing the PHP IntelliSense extension before adding that one? Commented Aug 27, 2018 at 0:46
  • Oh, I didn't know you already had a PHP extension. You certainly shouldn't have both at the same time because you'll get duplicate stuff everywhere. Commented Aug 27, 2018 at 6:15
  • @ÁlvaroGonzález Just wanted to let you know that PHP Intelephense works exactly as I hoped. Not sure why the PHP IntelliSense plugin didn't work. Maybe your comment would work as an answer to this question? Commented Aug 31, 2018 at 3:04

1 Answer 1

45

Visual Studio Code core does not include advanced PHP features, just syntax highlighting, simple code completion and code linting provided by the PHP binary as long as you have it installed. In short, the features you can configure with these directives:

// Controls whether the built-in PHP language suggestions are enabled. The support suggests PHP globals and variables.
"php.suggest.basic": true,

// Enable/disable built-in PHP validation.
"php.validate.enable": true,

// Points to the PHP executable.
"php.validate.executablePath": null,

// Whether the linter is run on save or on type.
"php.validate.run": "onSave"

For anything else you need to install a third-party extension.

My personal choice is PHP Intelephense. In particular, it supports docblock annotations, including magic properties:

/**
 * @property string $foo
 */
class Bar
{
}

... and inline types:

/** @var \Database $db */
$db->connect();
Sign up to request clarification or add additional context in comments.

5 Comments

I believe it is actively maintained at this time.
PHP Intelephense is awesome
php inteliphense is partially free and makes you pay premium for basic features like refarcorting. Better wait until MS catches up. As of 2021, it hasn't happened yet
Is there no good free alternative to Intelephense?
PHP IntelliSense

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.