php: wrapping arguments in functions

Hi everyone,

Is it possible to have phpstorm "wrap" og "Surround With..." arguments in ex. if statements? Like this:

if($argument) -> have it surround with ex. empty function call if(!empty($argument)) by doing something like this if($argument.empty) and hitting tab.


Kind regards

René Petersen

1 comment
Comment actions Permalink

Hi there,

>by doing something like this if($argument.empty) and hitting tab.

That's called Postfix code completion and unfortunately there is no template for your case ATM.

Consider watching those tickets (star/vote/comment) to get notified on any progress. You may ask for such postfix to be added in first ticket .. or maybe better -- create your own ticket (otherwise comments may get lost).


>ex. empty function call if(!empty($argument))

Right now you can do something like this via Intention quick fix (Alt+Enter on Windows/Linux .. or light bulb icon) .. but it has to be on variable itself. E.g.


(have caret placed somewhere on variable name; invoke Quick Fix menu, choose the right option)

It will become

if (!empty(argument)) {

As you can see -- it is not suitable for your case where variable is already located inside if condition (if you use it you will get nested if inside if condition).


The only working solution for now for your case is to create and use custom Live Template:

  • Create custom live template that will do such task -- use $SELECTION$ variable to denote that this is "surround" kind of template.
  • In your code -- select your $argument inside if condition
  • Invoke "Code | Surround with Live Template..." and choose right template to be used



empty() is not a function but language construct --


Please sign in to leave a comment.