Skip to content
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

Cannot declare class because the name is already in use #859

Closed
icanhazstring opened this issue Feb 3, 2023 · 13 comments
Closed

Cannot declare class because the name is already in use #859

icanhazstring opened this issue Feb 3, 2023 · 13 comments

Comments

@icanhazstring
Copy link

icanhazstring commented Feb 3, 2023

Bug report

Question Answer
Box version 3.16.0
PHP version 7.4, 8.0, 8.1
Platform with version whatever php:7.4-alpine is using :)
Github Repo - https://github.com/composer-unused/composer-unused
box.json.dist
{
   "base-path": null,
   "output": "build/composer-unused.phar",
   "files": [
       "config/container.php",
       "config/polyfill_symfony_di.php",
       "config/services.php"
   ],
   "compactors": [
       "KevinGH\\Box\\Compactor\\PhpScoper"
   ]
}
Output
$ make box
> docker compose run php7.4 php .phive/box compile --no-parallel

   ____
  / __ )____  _  __
 / __  / __ \| |/_/
/ /_/ / /_/ />  <
/_____/\____/_/|_|


Box version 3.16.0@adb282a 2022-02-13 23:54:13 UTC

// Loading the configuration file "/docker/composer-unused/box.json".                                                  

🔨  Building the PHAR "/docker/composer-unused/build/composer-unused.phar"

? Registering compactors
 + KevinGH\Box\Compactor\PhpScoper
? Adding main file: /docker/composer-unused/bin/composer-unused
? Adding requirements checker
? Adding binary files
   > No file found
? Auto-discover files? Yes
? Exclude dev files? Yes
? Adding files
   > 1067 file(s)
? Generating new stub
 - Using shebang line: #!/usr/bin/env php
 - Using banner:
   > Generated by Humbug Box 3.16.0@adb282a.
   > 
   > @link https://github.com/humbug/box
? Dumping the Composer autoloader

In ComposerOrchestrator.php line 172:
                                 
 Could not dump the autoloader.  
                                 

In ComposerOrchestrator.php line 175:
                                                                                                                                                                                            
 The command "'/usr/bin/composer' 'dump-autoload' '--classmap-authoritative' '--no-dev' '--ansi'" failed.                                                                                   
                                                                                                                                                                                            
 Exit Code: 255(Unknown error)                                                                                                                                                              
                                                                                                                                                                                            
 Working directory: /tmp/box/Box34800                                                                                                                                                       
                                                                                                                                                                                            
 Output:                                                                                                                                                                                    
 ================                                                                                                                                                                           
                                                                                                                                                                                            
 Fatal error: Cannot declare class __ComposerUnused__\Composer\InstalledVersions, because the name is already in use in /tmp/box/Box34800/vendor/composer/InstalledVersions.php on line 25  
                                                                                                                                                                                            
                                                                                                                                                                                            
 Error Output:                                                                                                                                                                              
 ================                                                                                                                                                                           
                                                                                                                                                                                            

compile [-c|--config CONFIG] [--debug] [--no-parallel] [--no-restart] [--dev] [--no-config] [--with-docker] [-d|--working-dir WORKING-DIR]

make: *** [box] Error 1

To reproduce:

  • checkout repository
  • make up
  • make update
  • make box

This might not even be related to this repository.
But I can't figure out what is happening here. The dump also didn't help a lot.

Seems like "something" in dependency chain changed.
Sadly I don't have a lock file to check what happened.

So this is more like a request for help 🙈
Thanks in advance!

@theofidry
Copy link
Member

I could only have a brief look:

  • looks like you're still on 3.16.0, which, errr... 4.2.0 is out 😓 I guess it's due to supporting PHP 7.4?
  • I would first try with your older release: if it fails to the culprit is very likely the Composer version you are using

@icanhazstring
Copy link
Author

If everything failed due to having newer composer version and 7.4 with 3.16 of box, I'll happily drip 7.4 😉

Thanks for some tips

@theofidry
Copy link
Member

Ah forgot to mention: do note that using a higher version of Box does not mean that your app aligns with Box's requirements.

If Box5 requires PHP 8.3, it can still, in theory, build an app which will work on PHP 5.3. The only caveats are:

  • if the requirement checker is enabled, it currently has been bumped to match Composer2 i.e. 7.2.34 as a minimum requirement
  • Box only works with Composer2

@icanhazstring
Copy link
Author

Ok. Thanks will try out some combinations. Maybe I'll find the culprit 😉

@icanhazstring
Copy link
Author

Ok, tried out every combination. With every php version, box 3.16 and 4.2, also downgraded composer to 2.0 and 2.5.
Everything returned the same issue in resulting:

Fatal error: Cannot declare class __ComposerUnused__\Composer\InstalledVersions

@icanhazstring
Copy link
Author

One thing I noticed which works, is if I set "exclude-dev-files": false everything works fine.

@theofidry
Copy link
Member

Oh if it's that setting it may be related to #580 or #654. I'll work on them for 4.3.0.

@icanhazstring
Copy link
Author

So there maybe no backward compatible change on old version right? So maybe I'll just go with dev deps enabled for now.

@theofidry
Copy link
Member

@icanhazstring I hope this fixed with #879. I unfortunately cannot upload the PHAR for you; I tried locally but this did not work as the project is still using PHP 7.4 with an old PHP-Scoper configuration.

If you want to test before the release you can always clone the repo and run composer compile though.

@icanhazstring
Copy link
Author

Thanks for the update. Will try it out 👍

@theofidry
Copy link
Member

Closing this as it has been fixed in newer versions. https://github.com/composer-unused/composer-unused should just work with the next Box release with composer-unused/composer-unused#592. It could already work with the current release if the --no-parallel option was added but at this point it might wait for it :)

@icanhazstring
Copy link
Author

Thanks for the draft. Will try and take over to upgrade and get the build back to work 👍

@theofidry
Copy link
Member

👍 I'll probably release 4.6.0 tomorrow or the day after. But meanwhile using --no-parallel should work (although x2 slower)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants