ZF-2240: Zend_Config_Xml can't find extended nodes (possibly only when empty)

Description

When using a file such as this:

<?xml version="1.0"?>

and loading it with Zend_Config_XML:

// Add Routes from config files $router = $front->getRouter(); $router->addConfig( new Zend_Config_Xml( 'config.xml', 'development' ), 'routes' );

it produces an exception: exception 'Zend_Controller_Router_Exception' with message 'No route configuration in section 'routes'' in /example/zend/library/Zend/Controller/Router/Rewrite.php:129

Running:

%svn update -r 6838 zend/library/Zend/Config

clears up the issue so the problem was introduced in revision 6906.

Looking at the source it my be due to the changes in the _toArray() method which assumes a node with no children is a string. My node has no children. Though this probably won't be the normal case I would think it should still work.

Comments

Here's a patch to fix it.

Index: zend/library/Zend/Config/Xml.php

--- zend/library/Zend/Config/Xml.php (revision 6950) +++ zend/library/Zend/Config/Xml.php (working copy) @@ -140,8 +140,13 @@ } } } else { - // object has no children: it's a string - $config = (string) $xmlObject; + if(isset($xmlObject['extends'])) { + // object is empty but it extends so we still need to process it + $config[$key] = (string) $value; + } else { + // object has no children: it's a string + $config = (string) $xmlObject; + } } return $config; }

This is a better patch. the last one causes NOTICE errors:

Index: zend/library/Zend/Config/Xml.php

--- zend/library/Zend/Config/Xml.php (revision 6950) +++ zend/library/Zend/Config/Xml.php (working copy) @@ -140,8 +140,11 @@ } } } else { - // object has no children: it's a string - $config = (string) $xmlObject; + // if the element extends then it isn't a string + if(!isset($xmlObject['extends'])) { + // object has no children and doesn't extend: it's a string + $config = (string) $xmlObject; + } } return $config; }

Sorry about that!

Fixed in svn r6965 on trunk and r6966 on release-1.0 branch.

Regards,

Rob...

Updating Fix Version to follow issue tracker conventions.