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:On PHP side, it works like usual:<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>
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.<?phpdefine('APPLICATION_PATH', dirname(__FILE__));$config = new Zend_Config_Xml($xmlString, 'production');echo $config->includePath; // Prints "/var/www/something/library"
Comments to this article
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.


Nice one! Does this also work for class constants like Foo::BAR?
Nope, that only works for usual PHP constants, as in .ini config files.
thank ben. it's usefull method.
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.
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!
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.