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

composer.json: empty string in autoloader-suffix #10720

Closed
WinterSilence opened this issue Apr 8, 2022 · 7 comments
Closed

composer.json: empty string in autoloader-suffix #10720

WinterSilence opened this issue Apr 8, 2022 · 7 comments
Milestone

Comments

@WinterSilence
Copy link

My composer.json:

{
    <...>
    "config": {
        "autoloader-suffix": ""
    }
}

Output of composer diagnose:

Checking composer.json: OK
Checking platform settings: OK
Checking git settings: OK
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com oauth access: OK
Checking disk free space: OK
...
Checking composer version: OK
Composer version: 2.3.4
PHP version: 7.4.27
...

When I run this command:

composer update -W -o

Actual result: class ComposerAutoloaderInit... {...}(autoload_real.php)

And I expected this to happen: class ComposerAutoloaderInit {...}

@Seldaek
Copy link
Member

Seldaek commented Apr 13, 2022

IMO having an empty suffix is a bad idea, as the point of the suffix is ensuring different projects get unique class names in case they coexist in the same process. So you can set it to your project's name or something if you like, but don't use empty.

Clarified this in #10725

@WinterSilence
Copy link
Author

WinterSilence commented Apr 14, 2022

@Seldaek in your case, bad idea is same suffix for loaders and no matter empty suffix or not. But in cases when uses single autoloader is's better then useless suffix.

@Seldaek
Copy link
Member

Seldaek commented Apr 14, 2022

I understand it's not what you wanted to hear, but I also don't see a huge problem with having this suffix set to something.. This classname shouldn't even appear anywhere in your code.

@WinterSilence
Copy link
Author

@Seldaek

This classname shouldn't even appear anywhere in your code.

Nope. Case: project declare N autoloaders, your code in vendor package. Question: how you get Composer autoloader to get registered namespaces?

@WinterSilence
Copy link
Author

@Seldaek I don't see a huge problem in omitted suffix in cases like my

@Seldaek
Copy link
Member

Seldaek commented Apr 14, 2022

I don't understand exactly your use case, but you can either use spl_autoload_functions() to retrieve it or use $loader = include 'vendor/autoload.php'; as the ClassLoader is returned from the autoload.php.

@WinterSilence
Copy link
Author

WinterSilence commented Apr 14, 2022

@Seldaek you right, I miss class of returned object. I'm was planed get instance by ComposerAutoloaderInit::getLoader().

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

No branches or pull requests

2 participants