Skip to content

PSR-4 settings on composer.json causes geoip2 to override all autoloading #54

@tbuteler

Description

@tbuteler

The package's composer.json has this for autoload settings:

"autoload": {
    "psr-4": {
        "GeoIp2\\": "src",
        "": "compat/"
    }
}

The fact that "" is set to the compat folder means that all autoloading will look for classes inside that folder before moving on to the correct path. I became aware of this because of numerous "No such file or directory" warnings on our servers, seen by this bit of process trace:

access("/home/project/vendor/geoip2/geoip2/compat/Illuminate/View/View.php", F_OK) = -1 ENOENT (No such file or directory)
access("/home/project/vendor/laravel/framework/src/Illuminate/View/View.php", F_OK) = 0

This goes on and on with all classes.

Am I doing something wrong on my side? I'm not even using geoip2, but it is required in one of my packages, and since composer puts on the autoload_psr4.php array just by being a requirement, this issue is present on all my projects.

I've tested this by putting a random class inside vendor/geoip2/geoip2/compact, i.e. vendor/geoip2/geoip2/compact/Namespace/Class.php, then calling it in my code. Even though another package (the actual "owner" of the class) states that Namespace/Class should be found within vendor/package/src/Namespace/Class, the PHP file inside geoip2 is what gets loaded.

Is there a way around this? Since the compat folder contains only a workaround for supporting 5.3, is it a worthwhile compromise to have this issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions