Code Completion#
The PHP editor analyses the entire workspace, it determines expressions type, function return type, property type, and local variables type. The inferred type information can be improved by providing further details using PHPDoc comments (see below).
Code completion is context-aware, scope-aware, type-aware, with the respect to conventions and additional heuristics.
Supported Notations#
The majority of the following notations are supported:
- PHPDoc type annotations.
- PHPDoc generic type annotations.
- Majority of PhpStan annotations in PHPDoc, templates, type aliases, generics, conditional return, type substitutions, and more.
phpstan.neon
,phpstan.neon.dist
,phpstan.dist.neon
files withtypeAliases
section.- Majority of Psalm type annotations in PHPDoc.
phpcs
comments for disabling and enabling errors, i.e.// phpcs:disable
and// phpcs:ignorefile
@mixin
PHPDoc annotation.- Jetbrains's PhpStorm
.phpstorm.meta.php
file with additional annotations. - Symfony and Laravel features (IntelliSense):
- deducing defined class aliases
- deducing provided services and facades
- Eloquent local scopes and extension methods
Completing Parentheses#
By default, completing a function name also completes parentheses and, if the function has any parameters to fill in, the keyboard cursor is placed inside them.
This behavior is controlled by the setting:
Alternativelly, the editor may complete default values for all the parameters. Set the setting to "parameters"
to do so:
Automatic Triggers#
The completion can be triggered manually (Ctrl+Space
by default) or automatically. The automatic triggers are:
- a letter completes available symbols in the current context
::
after a class/interface/trait name completes the type static members and constants.->
after an object instance completes the object's non-static members.\
as a part of a qualified name completes the namespaced (qualified) type name.$
as a first letter shows variables in the current function scope.- a letter or
Ctrl+Space
afternew
keyword completes possible class names - a letter or
Ctrl+Space
afterthrow new
completes only throwable classes - a letter or
Ctrl+Space
afteruse
keyword. -
` var $property;
function foo() { $x = eval('magic1()');
$x->query(); return eval('magic2()');
} } ```
Limitations#
The code editor may not resolve class_alias()
without constant expressions; therefore some aliased class names may not be included in the code completion.
The code editor won't recognize files containing a syntax error.
The code editor may not provide precise completions after eval()
expression or after classes being instantiated indirectly (using an expression new $classname
instead of a constant qualified name).