Re: How does Require deal with multiple files of the same name in




Jos van de Ven wrote:
Jos van de Ven wrote:

Correction for way 2 ( Sorry) :

"George Hubert" wrote:

[..]

2) Try all the directories and check for the file being loaded. If no
matching file is found then Include it (or throw an error if the file
doesn't exist in the path).


[..]

Way 2) does not always do that, since a file may be loaded again when
it is not in the search path.

Correction:

Way 2) has the disadvantage that it tries to load a file that is already loaded.
It should ignore the included action too avoid an error when the file is not there.

Jos

I tend to agree if no file in the search path can possibly match (so
include would fail anyway) a check could be made for any file and if
one exists assume it's correct (pssibly issuing a warning). The problem
I was trying to highlight is that method 1) could cause a file to load
even if a second file that is already loaded is the path as well, i.e.
the file is loaded test only returns true for the first match. I'm
coming round to the following. The is file loaded test should return
true;
1) If an absolute path is specified and that file is loaded.
2) If a relative path is specified, there is at least one file in the
search path that matches and any of the matching files are loaded
(possibly issuing a warning if more than one file is in the path).
3) If a relative path is specified, there are no files in the search
path that match but there is a file loaded that would match (possibly
issuing a warning that the file isn't in the current path).
4) If a relative path is specified, there is at least one file in the
search path that matches but none are loaded though there is a file
that matches in the search order and a system variable is set to a
never reload if any matching file is present mode.

I think that should cover all reasonable eventualities, at the expense
of an added variable for the user to worry about (though 99% of the
time I doubt it will matter).

George Hubert

.



Relevant Pages