Athlon1600 / php-proxy

A web proxy script written in PHP and built as an alternative to Glype.
https://www.php-proxy.com
MIT License
298 stars 158 forks source link

Global helper functions conflicts #32

Closed mcheptea closed 7 years ago

mcheptea commented 7 years ago

The helper function are in the global namespace and generate conflicts both with project and other packages. It's generally a good practice to isolate the scopes to avoid such conflicts.

The problem I'm currently having is with mockery/mockery and athlon1600/php-proxy in the same project.

Including php-proxy fails as follows:

app@0f9027110502:/var/www# php composer.phar require athlon1600/php-proxy      
Using version ^4.0 for athlon1600/php-proxy
./composer.json has been updated
> php artisan clear-compiled
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing athlon1600/php-proxy (4.0.2)
    Loading from cache

athlon1600/php-proxy suggests installing predis/predis (For caching purposes)
Writing lock file
Generating autoload files
> php artisan optimize
PHP Fatal error:  Cannot redeclare contains() (previously declared in /var/www/server/vendor/hamcrest/hamcrest-php/hamcrest/Hamcrest.php:104) in /var/www/server/vendor/athlon1600/php-proxy/src/helpers.php on line 16
Script php artisan optimize handling the post-update-cmd event returned with an error

Installation failed, reverting ./composer.json to its original content.

  [RuntimeException]                                                                                                                                                                                                                     
  Error Output: PHP Fatal error:  Cannot redeclare contains() (previously declared in /var/www/server/vendor/hamcrest/hamcrest-php/hamcrest/Hamcrest.php:104) in /var/www/server/vendor/athlon1600/php-proxy/src/helpers.php on line 16  

require [--dev] [--prefer-source] [--prefer-dist] [--no-progress] [--no-update] [--update-no-dev] [--update-with-dependencies] [--ignore-platform-reqs] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--] [<packages>]...

Note that hamcrest in this scenario is a dependency installed by mockery.

Athlon1600 commented 7 years ago

fixed:
https://github.com/Athlon1600/php-proxy/commit/4f79002ae8cd27f7935d95a02f500436b09f202d

mcheptea commented 7 years ago

@Athlon1600 this commit fixes this particular symptom. However it doesn't solve the underlying problem. You can easily create a static class named Helper say in a Proxy/Helpers namespace and refactor all the calls to the old global functions to use methods in this class.

It's not the prettiest solution but it should do the trick. :)