ZF-6209: Zend_Config_Ini ignores first line in .ini file


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}


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:

    public function testFirstLineOfIniIsLoaded()
        $filename = dirname(__FILE__) . '/_files/zf6209.ini';
        $config = new Zend_Config_Ini($filename);
        $this->assertEquals('b', $config->a);

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?

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:

environment = development
test = works


// ścieżka do aplikacji
    or define('APPLICATION_PATH', dirname(__FILE__));

// konfiguracje
$configurations = array

foreach ($configurations as $configuration)
        'configuration' . ucfirst($configuration),
        new Zend_Config_Ini(APPLICATION_PATH . '/config/' . $configuration . '.ini')

/* constant test */
    die('Already exists');
/* end */

// tryb wyświetlania strony
    or define('APPLICATION_ENVIRONMENT', Zend_Registry::get('configurationSystem')->get('environment'));

/* parse_ini_test */
$foo = parse_ini_file (APPLICATION_PATH . '/config/system.ini');

echo '
print_r ($foo);
echo '
'; /* end */ echo 'Should be "environment": '.APPLICATION_ENVIRONMENT.'
'; echo 'Should be "works": '.Zend_Registry::get('configurationSystem')->get('test'); exit;

Which displays:

    [environment] => development
    [test] => works

Should be "environment":
Should be "works": works

php_info ();

PHP Version 5.2.5

But... I just noticed that when .ini is in ANSI (not in UTF-8) everything is working fine.

This is a PHP bug ( which presumably will be fixed when 5.3 is released.

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.

If I do a Zend_Debug::dump($config->toArray()); then I see:

array(2) {
  ["a"] => string(1) "b"
  ["c"] => string(1) "d"

Ideas on how to fix the get() function are welcome!

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:

$file = parse_ini_file($filename);
if(array_key_exists('a', $file)) {
    echo "found the 'a' key";
} else {
    echo "didn't find the 'a' key";

outputs: didn't find the 'a' key

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.