Reputation: 2295
phpStorm and I agreee this is crazy but "wrong" file paths work while "right" ones fail. Basic structure.
|
|------classes(directory)
| |
| |
| Person.php
|
|------include(directory)
| |
| |
| db-connect.inc.php
| autoloader.inc.php
| helper.inc.php
|
|
|index.php
|etc.php
In index I use: (1)
include_once "include/autoloader.inc.php";
include_once "include/db-connect.inc.php";
include_once "include/helper.inc.php";
and in Person.php I would expect to use: (2)
include_once "../include/autoloader.inc.php";
include_once "../include/db-connect.inc.php";
include_once "../include/helper.inc.php";
But that gets is:
"Warning: include_once(../include/autoloader.inc.php): failed to open stream:
No such file or directory in C:\xampp\htdocs\dummy\classes\Person.php on line 2"
Bizarely (3)
include_once "/../include/autoloader.inc.php";
include_once "/../include/db-connect.inc.php";
include_once "/../include/helper.inc.php";
works and even more bizarely so does (4)
include_once "include/autoloader.inc.php";
include_once "include/db-connect.inc.php";
include_once "include/helper.inc.php";
even though we are up one directory level!
phpStorm flags 3 and 4 as errors (says "Path include/autoloader.inc.php not found" and "Include expression is not resolved") while (2), which is what I thought was "right", gets a nice big green tick but fails at debug or if directly accessed via http://localhost etc.
I always struggle with these path things but how come phpStorm and I agree and the real world say nope!
Guess I will have to put $_SERVER['DOCUMENT_ROOT']
in all over the place (lot easier with Storm instead of longhand!) but still a pain!
Upvotes: 2
Views: 187
Reputation: 1190
This is correct behaviour.
The page you loaded is in /
There you included a file from /includes
And now the file you have included is part of the page in /
So all includes in the included file are seen as relatives from /
not from /includes
and so on...
Upvotes: 2