Reputation: 1066
I am currently writing a project in PHPStorm and am having issues with the editor resolving paths that are prefixed with the server's document root. An example line of this might be:
require_once($_SERVER["DOCUMENT_ROOT"] . "/file.php");
This evaluates on the server and the page is built properly. PHPStorm however is complaining and saying "Path 'file.php' not found". I have looked into this issue and found threads online such as this that outline this situation. I have tried setting the Resource Root as recommended but have had no luck. Any help or guidance as to why this is happening would be appreciated. Thanks!
Edit: The document root evaluates to the local drive on my laptop that I am using to debug on a local Apache instance - "/Users/Me/PhpstormProjects/MyProject". This path is also set as the Resource Root in PHPStorm.
Upvotes: 1
Views: 2502
Reputation: 121
PHP Storm 2020
File -> Settings -> Languages & Frameworks -> PHP -> (Tab) Analysis
Field Include Analysis -> type your folder name here (e.g. www).
Upvotes: 2
Reputation: 165088
Evaluation of $_SERVER["DOCUMENT_ROOT"]
is not supported and currently there is no way to set it up somehow.
http://youtrack.jetbrains.com/issue/WI-3321 -- watch/star it to get notified on progress.
If you are happy to change your code a bit .. you could use this approach (works best if you have single point entry into your app -- e.g. all requests are routed via index.php
or alike):
define('DIR_ROOT', __DIR__);
-- since index.php
is usually placed in website root, it will point to the same folder as $_SERVER["DOCUMENT_ROOT"]
)require_once(DIR_ROOT . "/file.php");
If you are including classes this way -- maybe you should use autoloader instead (no need to do this manually)?
UPDATE ( 26/05/2015 ):
$_SERVER["DOCUMENT_ROOT"]
is supported since PhpStorm v8.0.3 and it's resolved to the project root, so if your web server root is located in actual subfolder (e.g. /some/path/project_root/www
) it will not get resolved correctly.
Upvotes: 7
Reputation: 330
The latest version of PHPStorm EAP fixes this bug.
You can get the last EAP here: https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Early+Access+Program
Upvotes: 0
Reputation: 198
http://php.net/manual/en/ini.core.php#ini.include-path, add the document root to the include path (echo $_SERVER["DOCUMENT_ROOT"];
)
can also do this at runtime using http://php.net/manual/en/function.set-include-path.php
might also want to see : http://www.jetbrains.com/phpstorm/webhelp/configuring-include-paths.html
Upvotes: 0