Search code examples
phpvisual-studio-codeintelephense

How to change the version of php in PHP Intelephense?


I'm using iis and vscode to do php work. I recently updated iis from php7.3 to php7.4. My problem is that vscode is still using php7.3. I googled how to change the version in vscode and almost all the resources say that there's a JSON file that can changed under php settings in File > preferences > settings. When I search for php I'm not seeing any of these options. What am I doing wrong?

enter image description here

enter image description here


Solution

  • You can set the value directly as seen in your screenshot. Entry is named PHP Version. If you do so for that particular workspace, a file will be created at

    {path_to_workspace}/.vscode/settings.json
    

    If you don't see the folder .vscode in Explorer, you have to change the settings in Explorer to see hidden folders.

    If you did set the PHP version on the page in your screenshot for that particular workspace then you should find in settings.json an entry that looks like the following

    {
      "intelephense.environment.phpVersion": "8.1.0"
    }
    

    change that to

    {
      "intelephense.environment.phpVersion": "7.4.0"
    }
    

    If you want to change the setting globally for all of your projects you can do the the following:

    Open Explorer, or command line (cmd.exe) and type or copy the following line

    %APPDATA%\Code\User\settings.json
    

    Usually this will start vscode if not already running and open settings.json.

    In that file at the beginning add after the opening bracket

      "intelephense.environment.phpVersion": "7.4.0",
    
      ... rest of the existing settings.json file here
    

    Before you change these files manually, it might be a good idea to make a backup of these files.