Req #62518 [Opn->Wfx]: Nested Includes
Edit report at https://bugs.php.net/bug.php?id=62518&edit=1
ID: 62518
Updated by: rasmus@php.net
Reported by: seregon at gmail dot com
Summary: Nested Includes
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
Package: *General Issues
Operating System: Neutral
PHP Version: 5.4.4
Block user comment: N
Private report: N
New Comment:
Normally for commonly included files you would do:
include 'my_includes/file.php';
and your include_path contains whatever the parent of the my_includes dir is.
That way that include works from everywhere.
And yes, making includes relative to the executing script was done on purpose
because it makes life much easier for a number of situations where you actually
want location-specific includes such as theming/templating systems.
Previous Comments:
------------------------------------------------------------------------
[2012-07-09 23:04:41] seregon at gmail dot com
Description:
------------
Scenario: File A includes File B, which in turn includes File C.
Problematic: The way PHP currently handles relative file paths (and this holds, from what I've
seen, for include, require, file_get_contents, and just about everything else; I'm reasonably
sure it's PHP's general relative file path handling I'm frustrated with) is by
resolving everything with the path of the ROOT calling script. Thus, if A & B are in the same
subdirectory, A can include B. If, however, A moves from the subdirectory, then A cannot include B
if C has any relative file paths. This is because C will call them with A's path when A starts
the chain of includes, and B's path when B starts it. Since A & B are not in the same
directory, this will always fail for at least one of them.
Expected result:
----------------
I can't really make any sense of why it was done this way, and I haven't found anything in
the documentation mentioning it. If this supports another worthwhile feature, then I'll gladly
be educated. Further, I'm open to suggestions to deal with it. However, as I've been
dealing with this the last few days, it's a very frustrating impediment to having a non-OO file
in a single location with handy functions in it. You have to copy the damn thing all over the file
system to have relative paths in it, which defeats the whole point of it having relative paths.
To me, this should proceed rather like functions (since it's by its nature procedural -- if
File C was OO this would be moot). Function C's calls should have a sort of "local
scope" whereby relative paths and perhaps other such things could be resolved, so that they can
be used no matter where they reside in the file system without having to hardcode absolute paths
(meaning they have to be updated when something else changes) or duplicate them across the fs
(meaning they can be thrown out of sync and have to be updated multiple times).
Actual result:
--------------
as above
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62518&edit=1
Thread (3 messages)