ZF-11004: Zend_Config doesn't recognize top-level arrays

Description

When Zend_Config is being instanciated with a top-level array, this isn't being recognized:

<?xml version="1.0" encoding="UTF-8" ?>

with toArray method and var_dump wrapper:

array(1) {
  ["tables"]=>
  array(1) {
    ["name"]=>
    string(9) "employees"
  }
}

Now, if you put this array inside another tag, array is recognized:

<?xml version="1.0" encoding="UTF-8" ?>

this is PHP output:

array(1) {
  ["dummytag"]=>
  array(1) {
    ["tables"]=>
    array(2) {
      [0]=>
      array(1) {
        ["name"]=>
        string(9) "employees"
      }
      [1]=>
      array(1) {
        ["name"]=>
        string(9) "vacations"
      }
    }
  }
}

I believe this has to do with the fact that Zend_Config starts iterating over the array without checking numeric indexes. It only checks whether the value is an array. This make child nodes to be recognized as arrays.

Comments

The example above is a bit confusing!


$xmlString = <<
EOT;
 
$config = new Zend_Config_Xml($xmlString);

Zend_Debug::dump($config->toArray(), 'First test:');

$xmlString = <<
EOT;
 
$config = new Zend_Config_Xml($xmlString);

Zend_Debug::dump($config->toArray(), 'Second test:');

First test: array(1) {
  ["tables"] => array(1) {
    ["name"] => string(9) "employees"
  }
}

Second test: array(1) {
  ["test"] => array(1) {
    ["tables"] => array(2) {
      [0] => array(1) {
        ["name"] => string(9) "employees"
      }
      [1] => array(1) {
        ["name"] => string(9) "vacations"
      }
    }
  }
}