Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge pull request zendframework/zendframework#2034 from RWOverdijk/h…
Browse files Browse the repository at this point in the history
…otfix/array-access-set

Fixed offsetSet bug with empty keys
  • Loading branch information
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Config.php
Expand Up @@ -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;
}
Expand Down
28 changes: 28 additions & 0 deletions test/ConfigTest.php
Expand Up @@ -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
*
Expand Down

0 comments on commit 86db540

Please sign in to comment.