Файли
openidea/docs/en/languages/php.mdx
T
Sameh Elhawaryтаsamehelhawary 65686e246e feat(lsp): send a server the documents it registers a selector for (#7558)
A language server marked dynamic-documents (Phoxite for PHP and Blade) is sent the other-language documents it registers a document selector for, such as a framework's YAML, XML or JSON files, alongside their own servers.

Malformed selectors match no documents, relative glob restrictions are kept, and withdrawing a selector closes the documents it opened.

Co-authored-by: samehelhawary <[email protected]>
2026-12-03 00:39:11 +08:00

137 рядки
13 KiB
Plaintext
Неформатований Анотація Історія

Цей файл містить неоднозначні символи Юнікоду
Цей файл містить символи Юнікоду, які можна сплутати з іншими символами. Якщо ви вважаєте, що це зроблено навмисно, можете сміливо ігнорувати це попередження. Щоб показати їх, скористайтеся кнопкою Escape.
---
title: "PHP"
description: "Intelephense and Phoxite, PHP interpreters and language level, Composer, PHPUnit and Pest, PHPStan, Xdebug debugging, Blade and Twig templates, and Laravel, Symfony and other framework support."
---
OpenIDEA highlights PHP files (`.php`, `.phtml`, `.phpt` and older `.php3`–`.php5`, plus files starting with `<?php` or a `php` shebang), Blade views (`.blade.php`) and Twig templates (`.twig`) out of the box. Completion, navigation, refactoring and diagnostics come from Intelephense. Composer scripts, PHPUnit/Pest suites and Laravel's development server are detected as run configurations, and Xdebug sessions run through the PHP Debug adapter. See the [support matrix](/en/languages/index) for other languages.
## Language servers
| Server | When it runs |
| ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `intelephense` | Default. Workspace root: `composer.json`, `.phpactor.json` or `index.php`. |
| `phpantom` | Fallback: used only while Intelephense is not installed. |
| `phpactor` | Fallback: used only while neither server above is installed. |
| `phoxite` | Alternative with its own framework, Blade and Twig support (see [Frameworks](#frameworks)): used while no server above is installed, or when you pick it in **Settings › Languages & Frameworks › Language Servers**. |
| `devsense-php-ls` | Alternative whose engine ships as native builds, so the server itself needs no Node or PHP: used while no server above is installed, or when you pick it in **Settings › Languages & Frameworks › Language Servers**. |
| `laravel-lsp` | Laravel projects only (below an `artisan` file): hover, definition and completion inside `config('…')`, `route('…')` and `view('…')`. |
A Blade view is served by the same servers as the project's PHP files. While Phoxite or DEVSENSE serves a project, `laravel-lsp` is not started: they answer the Laravel strings themselves.
Phoxite, where it is the project's PHP server, also reads files of other languages: Twig templates, `.env` files and Laravel's `lang/*.json`. It runs once for all of them, next to those languages' own servers, and is never started for a project without PHP.
Phoxite, once it finds one of these platforms in the project, also reads the platform's own files, so the names it knows in PHP (services, routes, hooks, configuration paths, language keys) complete and navigate there too:
| Platform | Files |
| --------- | ---------------------------------------------------------------------------------------------- |
| WordPress | JavaScript and TypeScript files, and `block.json` |
| Drupal | A module's or theme's `*.yml` (`*.services.yml`, `*.routing.yml`, `*.info.yml`, …) and `.info` |
| Magento | A module's `etc/**/*.xml`, layout and UI component XML, and `schema.graphqls` |
| Joomla | Manifests, forms and other XML, `language/**/*.ini` and `joomla.asset.json` |
Those files keep their own language servers (the YAML, XML and TypeScript ones); Phoxite adds its answers to theirs, in the project where it already runs for PHP.
DEVSENSE is usable without a licence for everyday code insight (completion, hover, go to definition, references, diagnostics, Laravel and Blade support); its refactorings and call/type hierarchy need a DEVSENSE licence.
Intelephense checks code against the project's PHP version (see [Language level](#language-level)) and indexes the stubs and include paths you configure.
## Setup
### Installing the tools
When a `.php` file opens and Intelephense is missing, a notification offers **Install**. The IDE installs it with npm into its own tools folder (needs `npm` or `pnpm` on `PATH`). Everything is also listed in **Settings › Languages & Frameworks › Language Servers**.
| Tool | Installed with |
| ------------------ | ------------------------------------------------------------------ |
| Intelephense | npm (`intelephense`) |
| PHPantom | GitHub release (`PHPantom-dev/phpantom_lsp`) |
| Phpactor | GitHub release (`phpactor/phpactor`, `phpactor.phar`); runs on PHP |
| Laravel LSP | GitHub release (`laravel/lsp`) |
| Phoxite | GitHub release (`samehelhawary/phoxite`) |
| DEVSENSE | npm (`devsense-php-ls`); needs Node.js to launch |
| PHP Debug (Xdebug) | Open VSX (`xdebug.php-debug`); needs Node.js to run |
### PHP interpreter
**Settings › Languages & Frameworks › PHP**, section **CLI Interpreter**:
- **PHP interpreter**: the `php` that runs scripts, PHPUnit, Composer, `artisan` and PHP-based servers such as phpactor. **Default** uses `php` on `PATH`. Its folder is put first on `PATH`, so `vendor/bin/phpunit` and other `#!/usr/bin/env php` scripts use the same PHP. The list includes PHP found on `PATH` (also versioned binaries like `php8.3`), Homebrew, phpbrew, phpenv, Laravel Herd, and on Windows XAMPP and Laragon.
- **Run in target**: run PHP and Composer commands locally or in a run target from **Settings › Build, Execution, Deployment › Run Targets**.
- The page shows the selected PHP's version and the loaded Xdebug version (or **Not installed**).
### Language level
**PHP language level** on the same page sets the version Intelephense checks against (5.6 to 8.5); newer syntax and functions are reported. **Auto** uses `config.platform.php` from `composer.json`, else the lowest version `require.php` allows. The status bar shows the current level; click it to switch.
Also on this page:
- **Include paths**: folders outside the project that Intelephense indexes too, such as a platform your module extends.
- **Additional stubs**: Intelephense stub sets on top of its defaults (for example `wordpress`). Each `ext-*` in `require` / `require-dev` of `composer.json` adds its own stubs automatically.
Phoxite receives the same settings: a language level you choose (for **Auto** it reads `composer.json` itself), the include paths, the additional stubs, and the PHP interpreter for the analysers it runs. Its own settings, such as `frameworks` to turn a framework's support on or off (`{ "frameworks": { "wordpress": "disabled" } }`), go in **Settings › Languages & Frameworks › Language Servers › Phoxite › Workspace Configuration**, or in a `phoxite.json` at the project root.
### Composer
In a Composer project without `vendor/`, or whose installed packages differ from `composer.lock`, a banner "Composer dependencies are not installed" appears above PHP files and `composer.json`, with **Install** (runs `composer install` on the configured PHP) and **Ignore**.
## Static analysis and formatting
- **PHPStan**: when the project has `vendor/bin/phpstan`, saved files are checked with it and its findings appear as diagnostics. The **PHPStan › Configuration file** setting picks the config; empty uses `phpstan.neon`, `phpstan.neon.dist` or `phpstan.dist.neon` in the project root.
- **PHP-CS-Fixer**: when a folder above the file has `.php-cs-fixer.php` or `.php-cs-fixer.dist.php` and the project has `vendor/bin/php-cs-fixer`, **Reformat Code** (`⌥⌘L` / `Ctrl+Alt+L`) uses PHP-CS-Fixer instead of the language server.
- **Alignment**: **Settings › Editor › Code Style › PHP › Alignment** has PhpStorm's **Align key-value pairs** (`=>` in multi-line arrays) and **Align consecutive assignments** (`=` in assignment statements on consecutive lines), both off by default. They apply after the language server or PHP-CS-Fixer formats, on save too; for a selection, only to its lines. A blank line, a comment line, another statement or a value spanning several lines starts a new group, and nested arrays align on their own.
## Run and test
Detected when the project has `composer.json` or a PHPUnit configuration:
- `composer <script>` for each script in `composer.json` (Composer event hooks are skipped); a script named `test` is a test configuration.
- **PHPUnit** (or **Pest**, when `vendor/bin/pest` exists) when there is `phpunit.xml`, `phpunit.xml.dist`, `phpunit.dist.xml`, a `phpunit/phpunit` or `pestphp/pest` dependency, or a runner in `vendor/bin`.
- `artisan serve` in Laravel projects.
The PHPUnit run configuration type has **Target**, **Configuration file**, **Test filter** and **PHPUnit options** fields.
**Run Context Configuration** (`⌃⇧R` / `Ctrl+Shift+F10`) runs a `*Test.php` file through the PHPUnit configuration, and any other PHP file with the selected interpreter. In `*Test.php` files and files under `test/` or `tests/`, gutter icons run a single test class or method, or a Pest test. Results appear in the test tree with **Rerun Failed Tests**. See [Testing](/en/guide/testing).
## Debugging
- **Symfony server** in Symfony applications (`symfony/framework-bundle`, `bin/console` and `public/index.php`): PHP's own web server, `php -S 127.0.0.1:8000 -t public`. The Symfony CLI is not needed.
Debugging uses PHP Debug (vscode-php-debug) with Xdebug. The selected PHP must load the Xdebug extension; the PHP settings page shows whether it does.
- **Debug** works on PHP files, PHPUnit/Pest, `artisan serve` and the Symfony server. The IDE turns on Xdebug for the session with `-d` options and a free port, so you don't need to edit `php.ini`, and another IDE listening on 9003 doesn't conflict.
- **PHP Remote Debug (Xdebug)** is a run configuration type that listens for incoming Xdebug connections (default port 9003), for requests served elsewhere such as php-fpm or a container. Its **Start the remote side with** field shows the matching `php -dxdebug.mode=debug …` command; for web requests use the `XDEBUG_SESSION` cookie or query parameter. Set **Local root** and **Remote root** to map paths.
See [Debugging](/en/guide/debugging).
## Frameworks
Run configurations and template highlighting work with any PHP server. The names a framework gives things (routes, views, services, configuration keys, hooks) are understood by Phoxite: where a section says "with Phoxite", pick it as the PHP server in **Settings › Languages & Frameworks › Language Servers**. Phoxite finds the frameworks of a project from `composer.json` and their marker files, and supports each one it finds.
### Laravel
- **Run and debug**: an `artisan serve` configuration.
- **Blade views** (`.blade.php`) are highlighted: HTML, directives, `{{ }}` and `{!! !!}` echoes and the PHP inside them, with `{{-- --}}` comments.
- **Laravel LSP**, with Intelephense: hover, definition and completion inside `config('…')`, `route('…')` and `view('…')`.
- **With Phoxite**: completion, navigation, Find Usages, rename and "undefined" warnings for route names, views, config keys, translation keys, environment variables, validation rules, Eloquent columns and relations, Livewire components and Inertia pages; completion, hover, signature help and navigation inside Blade views; Find Usages and Rename of a key in `.env` and in `lang/*.json`.
### Symfony
- **Twig templates** (`.twig`) are highlighted: HTML, with tags, expressions and `{# #}` comments; blocks fold.
- **With Phoxite**: completion, navigation and rename for route names, template names, services and parameters, translation keys and Doctrine fields; in Twig templates, completion, hover, navigation (to an extended or included template, a function, a filter, a route), rename, the outline, formatting and problems.
### WordPress, Drupal, Magento and Joomla
With Phoxite, in PHP: completion, navigation and Find Usages for the platform's names, such as WordPress hooks, shortcodes, options and block names, Drupal services, routes and permissions, Magento's events, configuration paths, ACL resources and layout handles, Joomla's language keys, layouts and form fields.
Without Phoxite, add a platform's stubs under **Additional stubs** (for example `wordpress`) and its folder under **Include paths**.
### CodeIgniter, Yii, CakePHP and Laminas
With Phoxite, in PHP: completion, navigation and Find Usages for the framework's names (routes, views or templates, config keys, translation messages, services and components), and the types of the services, models and view variables the framework provides.
## Limitations
- With Intelephense, PHPantom, Phpactor or DEVSENSE, Blade views and Twig templates are highlighted but get no code insight of their own (a Blade view is read as PHP); with Phoxite they do.
- Run with Coverage is not available for PHPUnit.
- Debugging needs the Xdebug extension in your PHP; the IDE does not install it.