views:

455

answers:

1

I am trying to include a variable in a .ini file setting by surrounding it with curly braces, and Zend is complaining that it cannot parse it properly on Linux. It works properly on Windows, though:

welcome_message = Welcome, {0}.

This is the error that is being thrown on Linux:

:  Uncaught exception 'Zend_Config_Exception' with message 'Error parsing /var/www/html/portal/application/configs/language/messages.ini on line 10
' in /usr/local/zend/share/ZendFramework/library/Zend/Config/Ini.php:181
Stack trace:
0 /usr/local/zend/share/ZendFramework/library/Zend/Config/Ini.php(201): Zend_Config_Ini->_parseIniFile('/var/www/html/p...')
1 /usr/local/zend/share/ZendFramework/library/Zend/Config/Ini.php(125): Zend_Config_Ini->_loadIniFile('/var/www/html/p...')
2 /var/www/html/portal/library/Ingrain/Language/Base.php(49): Zend_Config_Ini->__construct('/var/www/html/p...', NULL)
3 /var/www/html/portal/library/Ingrain/Language/Base.php(23): Ingrain_Language_Base->setConfig('messages.ini', NULL, NULL)
4 /var/www/html/portal/library/Ingrain/Language/Messages.php(7): Ingrain_Language_Base->__construct('messages.ini', NULL, NULL, NULL)
5 /var/www/html/portal/library/Ingrain/Helper/Language.php(38): Ingrain_Language_Messages->__construct()
6 /usr/local/zend/share/ZendFramework/library/Zend/Contr in

We are able to get the error to go away on Linux if we surround the braces with quotes, but that seems like a strange solution:

welcome_message = Welcome, "{"0"}".

Is there a better way to solve this issue for all platforms? Thanks for your help,

Dave

+5  A: 

What about having the whole message between quotes ?

A bit like this :

welcome_message = "Welcome, {0}."


Quoting the documentation of parse_ini_file (which Zend_Config_Ini might use) :

Note: If a value in the ini file contains any non-alphanumeric characters it needs to be enclosed in double-quotes (").

And, also (emphasis mine) :

Note: There are reserved words which must not be used as keys for ini files.
These include: null, yes, no, true, false, on, off, none.
Values null, no and false results in "", yes and true results in "1".
Characters {}|&~![()^" must not be used anywhere in the key and have a special meaning in the value.

Pascal MARTIN
Zend Config Ini does indeed use parse_ini_file. I recommend PHP configs for performance and flexibility but if using ini, this will work.
David Caunt
Surrounding the whole message in quotes seems to work great! Thank you so much for your help. I am curious about the performance issue with ini files, David.
Dave Morris
You're welcome :-) ;; about performances, you can cache the config object, if needed.
Pascal MARTIN
@David - If the value isn't quoted, it gets treated as a constant, which is why you can do this: `bootstrap.path = APPLICATION_PATH "/Bootstrap.php"`
Sonny