imposter
imposter copied to clipboard
Conflict between two projects using the same package with file autoloading
Let's assume we have a package with:
"autoload": {
"files": [
"src/functions.php"
]
},
Where this functions.php file content is:
namespace PackageName
function my_func() {}
Now, when two different projects load the same package, they may have other prefixes:
ProjectOne\Vendor\ProjectTwo\Vendor\
So in the first project which loads ealier you do:
ProjectOne\Vendor\PackageName\my_func();
which is fine, but the other:
ProjectTwo\Vendor\PackageName\my_func();
Gives function not found fatal error.
The reason why is because of both function.php files, despite changed namespace has the same content hash generated by composer autoloader. And because the file with given hash has been already loaded it doesn't load it again.
Any idea why this is happening? Does Imposter change the namespace after the Composer generates the file hashes?
Why PHP is loading 2 projects at the same time? In other words, why there is 2 root composer.json?
No no, it's two separate WordPress plugins