-
Notifications
You must be signed in to change notification settings - Fork 161
Description
Using { "extra": { "merge-plugin": { "include": [ "extensions/*/composer.json" ] } }
sometimes gives error of the form
Fatal error: Cannot redeclare <some function/class> (previously declared in <directory>/extensions/<name>/<file>:<line>) in <directory>/extensions/<name>/<file> on line <line>
when optimize-autoloader
is true
. EDIT: Also when optimize-autoloader
is false
.
I stripped down my MW-installation to the following MWE to demonstrate the issue:
EDIT: Here is an even more minimal example:
composer.json
:
{
"name": "test/test",
"require": {
"wikimedia/composer-merge-plugin": "2.0.1",
"test/dependency": "@dev"
},
"repositories": [{
"type": "path",
"url": "./test-dependency"
}],
"extra": {
"merge-plugin": {
"include": [
"extensions/*/composer.json"
]
}
}
}
test-dependency/composer.json
:
{
"name": "test/dependency",
"type": "mediawiki-extension",
"require": {
"composer/installers": "^2.0"
},
"autoload": {
"files": [
"Test.php"
]
}
}
test-dependency/Test.php
:
<?php
class Foo {};
END OF EDIT
composer.json
:
{
"name": "test/test",
"prefer-stable": true,
"require": {
"wikimedia/composer-merge-plugin": "2.0.1"
},
"config": {
"allow-plugins": {
"wikimedia/composer-merge-plugin": true,
"composer/installers": true
}
},
"extra": {
"merge-plugin": {
"include": [
"composer.local.json"
],
"recursive": true,
"merge-dev": false
}
}
}
composer.local.json
:
{
"require": {
"mediawiki/user-functions": "dev-REL1_35"
},
"extra": {
"merge-plugin": {
"include": [
"extensions/*/composer.json"
]
}
}
}
index.php
:
<?php
define('MEDIAWIKI', '1.35');
define('NS_MEDIAWIKI', 2);
require_once __DIR__ . '/vendor/autoload.php';
echo "When this is shown, the page is working";
With these files set up, reproduce the issue as follows:
- Run
composer update
twice. - Either run
php -S localhost:8000
and then go tolocalhost:8000
in your browser, or just runphp index.php
.
When you run composer update
once, everything works, but when done twice it does not.
In this case the files
./vendor/composer/autoload_static.php
and ./vendor/composer/autoload_files.php
look something like
$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
return array(
'7bb4d66942ef8c1728c8f742a0d5639d' => $baseDir . '/extensions/UserFunctions/UserFunctions.php',
'3661fc4b5b3581d0c7a3aa2f63bb491b' => $baseDir . '/extensions/UserFunctions/UserFunctions.php',
);
and
class ComposerStaticInit722b29a9c891bd933c9e56337f7bb753
{
public static $files = array (
'7bb4d66942ef8c1728c8f742a0d5639d' => __DIR__ . '/../..' . '/extensions/UserFunctions/UserFunctions.php',
'3661fc4b5b3581d0c7a3aa2f63bb491b' => __DIR__ . '/../..' . '/extensions/UserFunctions/UserFunctions.php',
);
/* A lot more that I ommitted */
}
respectively.
This forces composer to load these files two times, resulting in the error described above.
I use php
version 7.4.30
and composer
version 2.4.1
.