PHP Operator Assist
Use . as a typing shortcut for PHP object and static access operators. PHP Operator Assist converts the dot based on the expression before it:
| Type |
Becomes |
$user. |
$user-> |
$user->profile. |
$user->profile-> |
Route. |
Route:: |
App\Models\User. |
App\Models\User:: |
self. / static. / parent. |
self:: / static:: / parent:: |
It works in PHP files and Laravel Blade files.
String concatenation
By default, conversion only happens when the dot is directly next to the expression. This leaves the usual spaced concatenation syntax unchanged:
$message = $first . $second;
Dots inside strings and comments are ignored. Class detection uses PHP naming conventions: a class-like name whose final segment starts with an uppercase letter, and the keywords self, static, and parent, become ::. Lowercase class aliases are left unchanged because they are ambiguous with function names.
Settings
phpDotToArrow.enabled: turn conversion on or off (default true).
phpDotToArrow.onlyWithoutWhitespace: convert only when the dot directly follows the expression (default true). Turning this off can also convert spaced string concatenation.
Install from a VSIX
In VS Code, open Extensions, select … → Install from VSIX…, and choose the generated php-operator-assist-<version>.vsix file.
Develop and test
- Open this repository in VS Code.
- Press F5 to launch the Extension Development Host.
- Type a dot after an object variable or class name in a PHP or Blade file.
- Run
npm test to run the conversion tests.
To package the extension locally, install the VS Code Extension Manager and run:
npm install -g @vscode/vsce
vsce package
License
MIT. See LICENSE.