diff --git a/src/Config.php b/src/Config.php index ece2b09..11ec759 100644 --- a/src/Config.php +++ b/src/Config.php @@ -122,8 +122,13 @@ public function __get($name) public function __set($name, $value) { if ($this->allowModifications) { + if (is_array($value)) { - $this->data[$name] = new self($value, true); + $value = new self($value, true); + } + + if (null === $name) { + $this->data[] = $value; } else { $this->data[$name] = $value; } diff --git a/test/ConfigTest.php b/test/ConfigTest.php index 25eac99..cdb2dfa 100644 --- a/test/ConfigTest.php +++ b/test/ConfigTest.php @@ -388,6 +388,34 @@ public function testArrayAccess() $this->assertFalse(isset($config['db']['name'])); } + public function testArrayAccessModification() + { + $config = new Config($this->numericData, true); + + // Define some values we'll be using + $poem = array( + 'poem' => array ( + 'line 1' => 'Roses are red, bacon is also red,', + 'line 2' => 'Poems are hard,', + 'line 3' => 'Bacon.', + ), + ); + + $bacon = 'Bacon'; + + // Add a value + $config[] = $bacon; + + // Check if bacon now has a key that equals to 2 + $this->assertEquals($bacon, $config[2]); + + // Now let's try setting an array with no key supplied + $config[] = $poem; + + // This should now be set with key 3 + $this->assertEquals($poem, $config[3]->toArray()); + } + /** * Ensures that toArray() supports objects of types other than Zend_Config *