PhpStorm 2019.1 Help

Structural Search and Replace Examples

Searching for method calls

The simplest template to search for method calls is $Instance$->$MethodCall$($Arguments$). The Find tool window shows the detected method calls. If you need to locate a method call with the specific number of arguments, you can configure the Count filter for the $Arguments$ variable.

To navigate to the method call in the source code, double-click it in the Find tool window. PhpStorm opens the corresponding file in the editor and positions the caret at the method call.

Structural search method call.png

Searching for PHP classes

If you have a PHP class MyClass:

class MyClass {}

Then the simplest template to search for it is class $a$.

Searching for implementations of interfaces

If you have a PHP interface MyInterface and a class Implementation that implements it:

class Implementation implements MyInterface{}

Then the simplest template to search for the implementation is class $Class$ implements $SomeInterface$ {}

Searching for descendant classes

If you have a PHP class Parent and a class Descendant that extends it:

class Descendant extends Parent{}

Then the simplest template to search for Descendant is class $Class$ extends $AnotherClass$ {}

Searching for statements

The simplest template to search for if statements is if($var$){$code$}

As a result, the detected occurrences will be shown in the Find tool window, double-click the one you are interested in to navigate to the source code. PhpStorm opens the corresponding file in the editor and positions the caret at the statement.

Structural search if statement

Searching in comments and string literals

The simplest template to find comments or literals containing foo is: $SomethingWeWantToFind$ or "$SomethingWeWantToFind$". To find comments/strings containing some particular words (say, foo as a word), this should be specified as a text constraint.

Searching for XML and HTML tags, attributes, and their values

The simplest template to search for a tag is <$a$/>

By placing constraints on the variable $a$, you can specify which tags you want to find. For example, if you specify the text/regexp constraint app.+, you’ll find the tags whose names start with app.

A more versatile template for searching in XML and HTML is <$tag$ $attribute$="$value$"/> By using this template with properly specified search settings and constraints, you can find practically anything that may occur in XML or HTML. For example, if you specify the text/regexp constraint width for the variable $attribute$, you’ll find all the tags that have the width attribute.

Last modified: 26 July 2019

See Also