Constant support for Zend_Config_Xml

Tuesday, July 21, 2009

Today I added support for constants in Zend_Config_Xml. This new feature will be available in Zend Framework 1.9. It was added via a Zend_Config_Xml specific XML namespace. To give you an easy example of how that may work:
<config xmlns:zf="http://framework.zend.com/xml/zend-config-xml/1.0/">
    <production>
        <includePath><zf:const zf:name="APPLICATION_PATH"/>/library</includePath>
    </production>
</config>
On PHP side, it works like usual:
<?php
define('APPLICATION_PATH', dirname(__FILE__));
$config = new Zend_Config_Xml($xmlString, 'production');

echo $config->includePath; // Prints "/var/www/something/library"
Additionally, the "extends" attribute was also moved to this new namespace, making the NULL namespaced extends attribute deprecated until ZF 2.0, when it will be removed.

Comments to this article

  • Avatar of Ralf Eggert Reply Ralf Eggert Wednesday, July 22, 2009 8:16 AM

    Nice one! Does this also work for class constants like Foo::BAR?

  • Avatar of Ben Scholzen 'DASPRiD' Reply Ben Scholzen 'DASPRiD' Wednesday, July 22, 2009 9:03 AM

    Nope, that only works for usual PHP constants, as in .ini config files.

  • Avatar of Muhammad Reply Muhammad Thursday, September 3, 2009 2:39 PM

    thank ben. it's usefull method.

  • Avatar of Muhammad Reply Muhammad Sunday, November 29, 2009 5:11 PM

    It's good tools. but for first code of bootstrap not good because XML file have so time for pars and need cache before use.
    But this way is useful.

    • Avatar of René Pardon Reply René Pardon Saturday, May 29, 2010 5:53 PM

      I think it depends on your config file. If you have a large one it will take a long time to parse.

      I like this feature - constant support within xml files. Really awesome!

  • Avatar of James Zimmerman II Reply James Zimmerman II Friday, August 27, 2010 11:54 PM

    I just found this announcement but I've been an avid user of the XML format. Thank you so much for the constant addition, I really only use it for APPLICATION_PATH, but was really glad to see it added.

Leave a comment

Please note that your email address will not be shown, it is only used to fetch your avatar image from gravatar.com and for notifications.

 _                                  
| |__   __ _  __ _  ___  _   _  ___ 
| '_ \ / _` |/ _` |/ _ \| | | |/ _ \
| | | | (_| | (_| | (_) | |_| |  __/
|_| |_|\__,_|\__, |\___/ \__,_|\___|
             |___/