Go To Implementation in PhpStorm

At a round-table discussion with Ben Marks (of Magento fame), the developers from Class Llama mentioned that they had a gripe with the “Go to declaration” functionality in PhpStorm.

“Go to declaration” (default Cmd/Ctrl+click on a class name) is used so that you can quickly navigate through your codebase, to find the declaration of the code you are looking at. This is really useful functionality, and something I use every day, particularly when dealing with frameworks or other code I didn’t write personally. Find a type hint for a class I’m not familiar with? I simply Cmd+click it to be taken straight to its definition.

90% of the time, this is just fine, and its a real time saver for me, but there are use cases where this functionality is simply not helpful. Consider the following:

When we are looking at this code, it’s likely that we’ll want to learn more about the RequestInterface object that is being passed to the Consumer to understand fully what the dependency is here. Keep in mind that in the real world, the interface definition and both of the implementations would be in different files. Using “Go to declaration” here is not as useful, as seeing the source of the RequestInterface while useful, is probably not what we are looking to see. It’s much more probable that we will want to jump quickly to the code of the implementation of the interface that is being injected.

I agreed with this wholeheartedly, I’ve hit this snag myself many times, most often when I’m clicking on the RequestInterface injection in a Zend Framework application and I’m taken to the interface definition. I know that this is an instance of the PhpRenderer\Request object, but I would love an easy way to jump to that definition.

As usual in this situation, I agreed to speak to the developers, and (again, as per usual), when I got back to the booth I was lucky enough to have a developer right there for me to mention it to. It comes as no surprise that I learned that this functionality already exists. Instead of using “Go to declaration”, use the “Go to Implementation” action instead (default Cmd/Ctrl+Alt+B); this will ask you which implementation of the interface you wish to navigate to instead. Much more useful!

Go to implementation


I’m tempted to map this to a more natural key combination, I’m thinking something like Cmd+Shift+click to make navigating to where I want to go even easier.

Give it a try and let me know what you think.

— Gary and the PhpStorm Team

The Drive to Develop


About Gary Hockin

Gary Hockin has been creating code to power web applications for 15 years, the last three of them at an extraordinary level. He is handsome, talented, funny and articulate, and also extremely modest. Gary is a valued contributor to Zend Framework 2 and is a member of the community review team. He's married and has two wonderful children, and when he's not coding, writing about code, speaking about code or reading about code, he can usually be found in the pub playing pool.
This entry was posted in Cool Feature and tagged . Bookmark the permalink.