Declaration

When editing a PHP file within a php project, it will not allow me to goto declarations. In my code I have something like:
require_once 'include/Sugar_Smarty.php';

When I have my mouse in the "include/SugarSmarty.php" part of the code I hit Command+B and it says that "Path "include" not found".

Is there anything I need to do differently to get this to work? I test this under netbeans and it works fine with the same project. So, I am thinking I just don't have something configured correctly.

Thanks!

3 comments
Comment actions Permalink

Hi Scott,

When editing a PHP file within a php project, it will not allow me to goto declarations. In my code I have something like:
require_once 'include/Sugar_Smarty.php';

This will work if this file is relative to the current file and you need to click on file name, e.g.:
PROJECT_ROOT/Current_File.php
PROJECT_ROOT/include/Sugar_Smarty.php

But generally speaking: you need to provide more information if you expect to receive some useful comments/advices and not wild guesses. Please describe your project (screenshots are welcome), e.g. folder structure, where files are located (relative to the projects) and other relative information.

If you can create some small standalone project that describes this project and share it here so me (or somebody else) can have a look locally ... that would be even better.


BTW, have you tried using "Navigate | File..." or "Navigate | Class..." ? In my opinion it is better suited for jumping between files (yes, some typing is required, but can be invoken from anywhere in a file).

0
Comment actions Permalink

You are correct - I probably needed to provide a little more information. I was thinking it was just a switch in the settings that I was missing or something like that.

I have attached a screenshot of another example of where I am trying to jump to the declaration from the modules/Accounts/Account.php file, to the data/SugarBean.php file. It still gives me the "path not found". The folder structure is pretty straightforward as it is pointing to the ~/Sites/htdocs/cfm/version_4.0/ directory for the main project and the file is located in the ~/Sites/htdocs/cfm/version_4.0/data/ directory.

I loaded the same project type (a new project from existing files) into phpstorm and netbeans. It found the declarations in netbeans (although I can't stand using that editor. Way to slow) but not in phpstorm.

So, my understanding is that phpstorm just doesn't have this ability. Am I correct? Or, I should say, it has the limited ability to do this as long as the first file is located at the root directory. But, it you go into one folder, then, you are pretty much out of luck. Correct?



Attachment(s):
Screen Shot 2012-11-12 at 3.51.55 PM.png
0
Comment actions Permalink

My example (file structure) works fine. Here is real example:

Current file: PROJECT_ROOT/test.php
Referenced file: PROJECT_ROOT/testing/test2.php

Once again: referenced file is relative to the current file, not project root.

screen01.png

Now, back to your screenshot/details.

So, my understanding is that phpstorm just doesn't have this ability. Am I correct? Or, I should say, it has the limited ability to do this as long as the first file is located at the root directory. But, it you go into one folder, then, you are pretty much out of luck. Correct?

It will work with relative files (does not matter where current it is located -- in root folder or subfolder -- as long as referenced file can be found in path relative to current one).

Yes, it will not work as you expecting without changing your code. These days almost everyone is using some sort of autoloading mechanism, so explicit require/include is a rare thing. Therefore devs do not seem to spend much of their time in this particular direction: http://youtrack.jetbrains.com/issues/WI?q=%23Star+%22Unresolved+include%22

If you wish -- you can declare some constant (during runtime) that will point to website root (define ('ROOT_DIR', __DIR__);  somewhere, e.g. in index.php or in some file that sits in root (or close) and gets execute on every request -- e.g. bootsrap.php or similar). Then you can use it in include/require statements -- this will make all paths absolute (slightly faster include/require processing, can make a difference of very busy sites) ... and it works during development (PhpStorm can evaluate what __DIR__ means for constants, as long as it is not used in complex calculations): include_once ROOT_DIR . '/data/SugarBean.php'; (of course, I perfectly understand that this not really an option for already existing large project).

0

Please sign in to leave a comment.