From 8c0d4857ef9e788206485c982adcfeeb3dfca92f Mon Sep 17 00:00:00 2001 From: nevvermind Date: Sun, 31 May 2015 15:44:12 +0100 Subject: [PATCH] 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); }