ZF-6209: Zend_Config_Ini ignores first line in .ini file
Description
When ini file looks like: {quote} a = b c = d {quote}
and php code looks like: {quote} $a = new Zend_Config_Ini ( APPLICATION_PATH . '/config/file.ini' );
echo $a->a; {quote}
nothing is displayed. But when ini file looks like: {quote} ; Foo a = b c = d {quote}
above php code will return: {quote} b {quote}
Comments
Posted by Rob Allen (rob) on 2009-04-05T02:26:58.000+0000
I've just tested this and it works for me.
I created this INI file (zf6209.ini) which has two lines in it: {{a = b}} {{c = d}}
and this test method within the Zend_Config_IniTest class:
This worked as expected.
Can you check this too please?
Can you tell me which line endings you have in your ini file and which PHP version you are using on which OS?
Posted by Frost (frost) on 2009-04-05T07:11:46.000+0000
Zend Tests doesn't work for me. I wasted over an hour trying to run it... nevermind.
I prepared
in UTF-8 on Windows XP using Notepad++. Line endings: [CR][LF].
Content of file.ini:
bootstrap.php:
'; /* end */ echo 'Should be "environment": '.APPLICATION_ENVIRONMENT.''; echo 'Should be "works": '.Zend_Registry::get('configurationSystem')->get('test'); exit;
Which displays:
php_info ();
Posted by Frost (frost) on 2009-04-05T07:16:06.000+0000
But... I just noticed that when .ini is in ANSI (not in UTF-8) everything is working fine.
Posted by Rob Allen (rob) on 2009-04-05T07:35:09.000+0000
This is a PHP bug (http://bugs.php.net/bug.php?id=45991) which presumably will be fixed when 5.3 is released.
Posted by Frost (frost) on 2009-04-05T07:49:57.000+0000
But strange is fact that simple parse_ini_file() on UTF-8 ini file works fine, but the same function in Zend_Config_Ini class doesn't.
Posted by Rob Allen (rob) on 2009-04-05T11:48:08.000+0000
If I do a Zend_Debug::dump($config->toArray()); then I see:
Ideas on how to fix the get() function are welcome!
Posted by Rob Allen (rob) on 2009-04-05T11:56:14.000+0000
A little more investigation with var_dump() shows that the key "a" is actually a 4 byte string and that the "c" key is a 1 byte string. I've no idea why and suspect that it's related to parse_ini_file() as the following code:
outputs: didn't find the 'a' key
Posted by Rob Allen (rob) on 2009-04-05T12:11:37.000+0000
Can't fix at Zend_Config level. Workaround is to use UTF8 files without a BOM marker or to have a comment / blank line as first line of file if you must have a BOM marker.