I'm going to start by apologizing because I'm a little fuzzy on the terminology here.

I'm evaluating PHPStorm for use at work. Normally I use Eclipse because it's free and it works well most of the time. But I thought I'd give PHPStorm a shot. It's got some really nice features and integrates with Git pretty nicely.

But for whatever reason, I can't get code tracing/ctrl-click-on-a-function-and-it-takes-me-to-the-function-definition working on PHPStorm. I'm working in Magento 2 and that's a bit of a deal breaker for me.

So as an example, let's say I've got this phtml file


/** @var $block \MyCompany\MyModule\Block\Foo */

$helper = $block->_fooHelper;
$bar = $helper->doSomethingCool();


<h2><?php echo $bar; ?></h2>

In Eclipse, I can ctrl-click on the doSomethingCool() function and it'll open up the class for _fooHelper and take me right to the function definition. But in PHPStorm all I get is a message saying

"Method 'doSomethingCool' not found. Referenced method is not found in subject class."  

I've searched around and ran the 'Detect PSR-0 Namespace roots" which came back and labeled the vendor and app/code folders as PSR-0 roots and then ran "Invalidate Cache/Restart" to reindex but I still get the same message.

Any ideas what I need to do to get the code tracing functionality I described working in PHPStorm?

EDIT: I just found that code tracing (i.e. ctrl-click on a function call) works with a type hinting pointing to the vendor folder like

/** var $block \Magento\Backend\Block\Template */

but does not work if it's pointing to something in the app/code folder like

/** var $block \MyCompany\MyModule\Block\Foo */
  • 1
    Can it find the class itself (can you go to the class by Ctrl+click from the phpdoc)? As I understand the method really exists and there is no mistake here. Is the method public?
    – BuskaMuza
    Commented Apr 6, 2016 at 21:59

1 Answer 1


Namespace root is your most likely problem. PhpStorm absolutely supports the feature you're looking for, and it should work out of box.

Make sure your project encompasses the entire source code, then tell PhpStorm where to go looking, if it wasn't able to work it out on its own. See: https://www.jetbrains.com/help/phpstorm/2016.1/configuring-php-namespaces-in-a-project.html#d140255e161

Configuring Namespace Roots Manually

Open the Settings / Preferences Dialog by choosing File | Settings for Windows and Linux or PhpStorm | Preferences for OS X, and click Directories under Project:. The right-hand pane of the Directories page that opens shows all the content roots configured in the project. As a rule, there is one content root which is the root folder of the current project.

The central pane shows all the folders under the selected content root. Select the folder to be treated as the namespace root and click Sources.

It is perfectly fine to configure multiple source roots: PhpStorm will treat each of those as a namespace root and provide namespace hints for files underneath them. For example every subfolder of a vendor folder can be marked as a namespace root. In the example below, we have two namespace roots: one for the actual application and one for a vendor folder

At minimum, you want to set the 'vendor' folder as Sources, plus the app/code folder if it exists. Under normal circumstances, every module (and namespace) should be within those two locations.

  • I double checked and the app/code folder and the vendor folders are marked as sources and still no dice. I just updated my original post with something I just found though.
    – Mike Levy
    Commented Apr 7, 2016 at 15:45
  • @MikeLevy: Interesting. Don't know what to tell you, except that something is clearly wrong with the namespace root for app/code. Try recreating the project, perhaps?.
    – Ryan Hoerr
    Commented Apr 7, 2016 at 16:13
  • 1
    I tried that yesterday. I deleted the project, deleted the .idea folder from the doc root, went through all the steps to set it back up and pretty much ended up right back where I'm at now. I've got a forum post going with Jetbrains in parallel with this one so if they figure it out. I'll be sure to update this post.
    – Mike Levy
    Commented Apr 7, 2016 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.