Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Force-loading vendor autoload causes dependency conflicts #38

Open
ryanshoover opened this issue Jul 17, 2020 · 0 comments
Open

Force-loading vendor autoload causes dependency conflicts #38

ryanshoover opened this issue Jul 17, 2020 · 0 comments

Comments

@ryanshoover
Copy link
Contributor

ryanshoover commented Jul 17, 2020

We require our autoload to load, even if all the dependencies we need are already loaded. This can cause fatal errors if another WordPress plugin has already loaded a different version of our dependencies.
https://github.com/awslabs/aws-for-wordpress/blob/master/includes/class-amazonpolly.php#L162

For example, guzzle released a breaking change in 6.5.0 that changed the VERSION constant to MAJOR_VERSION. If both our guzzle version (6.4.1) and a later version of guzzle are loaded, then fatal errors can get triggered because of mixed dependencies.

To recreate

  1. Set up a WordPress site that has a composer.json similar to below:
    {
    	"name": "wordpress/test",
    	"type": "project",
    	"description": "WordPress test instance",
    	"repositories": {
    		"wpackagist": {
    			"type": "composer",
    			"url": "https://wpackagist.org"
    		},
    		"s3uploads": {
    			"type": "vcs",
    			"url": "git@github.com:humanmade/S3-Uploads.git"
    		}
    	},
    	"require": {
    		"composer/installers": "^1.9",
    		"humanmade/s3-uploads": "2.2.2",
    		"wpackagist-plugin/amazon-polly": "4.2.1"
    
    	}
    }
  2. In wp-config.php, add require vendor/autoload.php
  3. Run wp plugin list
  4. See a fatal error like
    PHP Fatal error:  Uncaught Error: Undefined class constant 'MAJOR_VERSION' in     /var/www/html/vendor/guzzlehttp/guzzle/src/Utils.php:121
    Stack trace:
    #0 /var/www/html/vendor/guzzlehttp/guzzle/src/functions.php(61): GuzzleHttp\Utils::defaultUserAgent()
    #1 /var/www/html/wp-content/plugins/amazon-polly/vendor/guzzlehttp/guzzle/src/Client.php(194): GuzzleHttp\default_user_agent()
    #2 /var/www/html/wp-content/plugins/amazon-polly/vendor/guzzlehttp/guzzle/src/Client.php(75): GuzzleHttp\Client->configureDefaults()
    #3 /var/www/html/wp-content/plugins/amazon-polly/vendor/aws/aws-sdk-php/src/Handler/GuzzleV6/GuzzleHandler.php(26): GuzzleHttp\Client->__construct()
    #4 /var/www/html/vendor/aws/aws-sdk-php/src/functions.php(279): Aws\Handler\GuzzleV6\GuzzleHandler->__construct()
    #5 /var/www/html/wp-content/plugins/amazon-polly/vendor/aws/aws-sdk-php/src/Sdk.php(417): Aws\default_http_handler()
    #6 /var/www/html/wp-content/plugins/amazon-polly/admin/AmazonAI-Common.php(284): Aws\Sdk->__construct()
    #7 /var/www/html/wp-content/plugins/amazon-polly in /var/www/html/vendor/guzzlehttp/guzzle/src/Utils.php on line 121
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant