maxmind / GeoIP2-php

PHP API for GeoIP2 webservice client and database reader
https://maxmind.github.io/GeoIP2-php/
Apache License 2.0
2.33k stars 276 forks source link

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

Closed tbuteler closed 9 years ago

tbuteler commented 9 years ago

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?

oschwald commented 9 years ago

Thanks for reporting this. This should be fixed in #55 and should be in our next release.

oschwald commented 9 years ago

This is fixed in 2.3.2.