Path not found despite configured resource root

I've searched this forum but coudn't find any relevant answer to this, so here I go:

Despite setting a resource root inside my project I keep getting "Path ... not found" warnings from PHPStorm. But only for some resources, not for all. This is quite annoying and possibly interferes with some automatic tasks related to code analysis.

As shown in the attached screenshot, a resource root has been set, but PHPStorm doesn't find the direct folders underneath it. Resource root is "scripts", the requested include path starts in "shared", which is a direct sibling of "scripts". I habe also tried an absolute include path starting with "/shared/...." which doesn't change anything.

Am I doing something wrong or is this a bug?

Thanks in advance,
Roman

8 comments

Forgot the attachment, here it is.




Attachment(s):
phpstorm-path-not-found.gif
0

Hi Gunter,

Resource Roots are for web resources (images/javascript/etc) and not for PHP code (include/require statements). If no explicit absolute or relative path is provided, then path relative to current file is assumed (which is your case).

You can use one these techniques to provide absolute + relative combo:

require __DIR__ . '/../path/to/your/required/file.php';


or (depends on your code) -- if you have single entry script (everything goes trough index.php)

index.php (or another KEY file)

define ('ROOT_DIR', __DIR__);

another_file.php

require ROOT_DIR . '/path/relative/to/the/website/root/file.php';

This will result in absolute path to the file.


Generally speaking you may just disable this inspection (Settings | Inspections | PHP | General | Unresolved include) or suppress warning for that line (via Alt+Enter on error/warning), as there are quite a few cases where it currently does not work properly. Plus, personally for me, it is not that useful overall.

2

Hi Andriy,

thanks for your quick reply and for your suggestions.

Unfortunately, I'm not allowed to change the form of the include statements (I'm just a sub dev in this project and the statements are pre-defined to work with a specific server configuration). I was hoping that it would be possible to adapt the IDE to the needs of my code, not the other way around. ;)

0

Currently you will not be able to achieve this as IDE uses a bit different logic than actual PHP during execution (at the end of the day IDE provides static analysis only and cannot foresee all possible runtime configurations, especially if they are linked to a specific server configuration) -- with the way how your require statements are written it will only search for such file in path relative to project root or current file itself (it's how it works in current version).

My personal opinion: just disable such inspection.


Anyway: you may file your ideas as Feature Requests / Bug Reports directly to the Issue Tracker, but please check for existing tickets first (keyword: unresolved include).

0

I have this same problem.  When I originally created the project I had a different root folder on the server. Since then that Root has changed, but PHPstorm insists on regarding the old directory as the site's Root.

Is there seriously no way to tell the program what the server root is?

 

0

@Stephen Rider

Please describe your situation better -- some screenshots that would illustrate the issue are more than welcome.

Right now I'm confused/ simply do not understand the actual issue (what exactly you want to change and in what context/functionality).

0

@Stephen and @Mail

As I understand it, what you're trying to achieve is to tell the IDE where `include` and `require` etc look for files. Obviously the runtime manages to get it right, but for reasons you stated PhpStorm is a bit confused. Well, fret no more, just add the actual web root to the list of include paths under Settings/Preferences → Languages & Frameworks → PHP and presto, you have an IDE that works with you instead of against you :-)

 Documented here: configuring-include-paths.

4

Please sign in to leave a comment.