Postfix code completion is a handy feature that lets you transform an existing expression into a different one, based on a postfix you specify after the dot.
For example, to iterate over an object, use the fe postfix after your expression:
Postfix completion has existed in PhpStorm since version 9, but has only provided a limited number of predefined templates. In PhpStorm 2018.2, you can create postfix completion templates yourself, tailoring them for your project and your coding style.
To start creating a new postfix template, navigate to Preferences | Editor | General | Postfix Completion, click + , and select PHP:
Inside your template, use the $EXPR$ and the $END$ variables. The former will capture the expression before the dot, while the latter will define the position of the caret after the template is expanded:
Let’s apply the created template:
As you can see, PhpStorm has detected two expressions that are applicable for the template, so it has prompted us to choose one. If you need to always apply your template to the entire expression without selecting the scope for it every time, enable the Apply to the topmost expression option when creating a template. This way, the topmost applicable expression will be selected automatically.
If you have any feedback to share with us, please leave your comments to this blog post or in our public issue tracker. Stay tuned as the PhpStorm 2018.2 release is just around the corner!
Your JetBrains PhpStorm Team
The Drive to Develop