imposter icon indicating copy to clipboard operation
imposter copied to clipboard

Conflict between two projects using the same package with file autoloading

Open jakubmikita opened this issue 5 years ago • 2 comments

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?

jakubmikita avatar Mar 13 '20 13:03 jakubmikita

Why PHP is loading 2 projects at the same time? In other words, why there is 2 root composer.json?

tangrufus avatar Mar 13 '20 14:03 tangrufus

No no, it's two separate WordPress plugins

jakubmikita avatar Mar 13 '20 16:03 jakubmikita