From 8c0d4857ef9e788206485c982adcfeeb3dfca92f Mon Sep 17 00:00:00 2001 From: nevvermind Date: Sun, 31 May 2015 15:44:12 +0100 Subject: [PATCH 1/2] Fix "Invalid argument supplied for foreach()" on a new PlaformRepository obj This happens on "new PlatformRepository(array($somePackage))". The parent constructor calls "\Composer\Repository\ArrayRepository::addPackage()", which, on a brand new repo object, further calls "\Composer\Repository\PlatformRepository::initialize()" and finally this iterates over a NULLd "$this->overrides", triggering the error. --- src/Composer/Repository/PlatformRepository.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Composer/Repository/PlatformRepository.php b/src/Composer/Repository/PlatformRepository.php index 4afd3d4e9..eb4c471ec 100644 --- a/src/Composer/Repository/PlatformRepository.php +++ b/src/Composer/Repository/PlatformRepository.php @@ -31,12 +31,11 @@ class PlatformRepository extends ArrayRepository * * @var array */ - private $overrides; + private $overrides = array(); public function __construct(array $packages = array(), array $overrides = array()) { parent::__construct($packages); - $this->overrides = array(); foreach ($overrides as $name => $version) { $this->overrides[strtolower($name)] = array('name' => $name, 'version' => $version); } From ec00a4dbfaecad0662c82afd2644f720dd99bef0 Mon Sep 17 00:00:00 2001 From: nevvermind Date: Wed, 3 Jun 2015 00:06:24 +0100 Subject: [PATCH 2/2] Set the platform overrides first --- src/Composer/Repository/PlatformRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Repository/PlatformRepository.php b/src/Composer/Repository/PlatformRepository.php index eb4c471ec..5c7bd8a67 100644 --- a/src/Composer/Repository/PlatformRepository.php +++ b/src/Composer/Repository/PlatformRepository.php @@ -35,10 +35,10 @@ class PlatformRepository extends ArrayRepository public function __construct(array $packages = array(), array $overrides = array()) { - parent::__construct($packages); foreach ($overrides as $name => $version) { $this->overrides[strtolower($name)] = array('name' => $name, 'version' => $version); } + parent::__construct($packages); } protected function initialize()