Tutorial: Finding usages of implemented and overridden PHP methods
In the PHP context, PhpStorm applies the Find Usages functionality to implemented and overridden methods. Let's consider the following example:
-
Create an interface, an abstract class that implements it, and two classes that extend the abstract class:
Create an interface
MyInterface
with afoo()
method.Create an abstract class
MyAbstractClass
that implementsMyInterface
.Create a class
MyClass
that extendsMyAbstractClass
and implement thefoo()
method required by the interface and overrides the methods of the parent class.Create a class
MyClassWithDelegate
that extendsMyClass
and implementfoo()
with a delegate.Create variables
$b
and$c
that callfoo()
fromMyClass
andMyClassWithDelegate
respectively:
<?php interface MyInterface { //press Alt-F7 on foo() here public function foo(); } abstract class MyAbstractClass implements MyInterface { public function foo () { // TODO: Implement foo() method. } } class MyClass extends MyAbstractClass { public function foo() { parent::foo(); // TODO: Change the automatically generated stub echo "foo"; } } class MyClassWithDelegate extends MyClass { public function foo() { foo(); } } $b = new MyClass(); $b->foo(); $c = new MyClassWithDelegate(); $c->foo();
From
MyInterface
, invoke Find Usages forfoo()
by pressing Alt+F7 or choosing on the main menu. By default, PhpStorm shows only the delegates to the super method and method calls:To additionally find the methods that implement or override the base method, click in the Find tool window. Then in the Find Usages. Method Options dialog that opens, select the Include overloaded methods checkbox and click Find. As a result, all the usages of the
foo()
method are found in all the classes that implement or extendMyInterface
: