New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Explicitly check if a file has already been required before requiring it #4186
Explicitly check if a file has already been required before requiring it #4186
Conversation
Wouldn't it be easier instead if perhaps the Composer autoloader defined a constant (e.g. Basically approaching the situation from a different angle. Just trying to add more ideas. :-) |
@alcohol The two autoloaders might load different files (e.g., if you install PHPUnit globally and Guzzle locally), so I'm not sure a simple flag would be useful. |
What if the value of it was the resolved path to the autoloader? For
|
I don't believe that would solve the issue reported in #3003, which was that the same file, existing in two locations on disk, could be included by two separate autoloaders. |
I don't understand how this is relevant? Globally installed doesn't mean it is always loaded. You would still have to explicitly include |
That's correct, and that is the issue that was reported. #3003 (comment) |
@alcohol the problem occurs when a tool installed globally (PHPUnit for instance) also loads the autoloading of your project after loading the global one |
@stof Do you think this is a good way to solve the problem? I used file checksums instead of logical identifiers so that accidentally loading two versions of the same package would continue to cause a failure, but using something like |
…luded once per package even if exactly the same, refs #4186
Thanks! |
This would address #3003 by assigning an identifier to each included file during
AutoloadGenerator::dump
. Currently, this identifier is the value returned bymd5_file
(to address the concern raised in guzzle/guzzle#676 (comment)), but it could also be a logical file address such as$packageName::$relativePath
, e.g.guzzlehttp/guzzle::src/functions.php
.This is preferable to simple changing
require
torequire_once
because it prevents two copies of the same file from being loaded, as would happen if a globally installed package loads project's autoloader and both rely on the same package. A known example of this is using a globally installed copy of CodeCeption on a project requiring Guzzle.Would also address:
guzzle/guzzle#1146
guzzle/psr7#22