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

Issue Type: Bug Created: 2009-04-03T14:15:01.000+0000 Last Updated: 2009-04-05T12:11:37.000+0000 Status: Closed Fix version(s): Reporter: Frost (frost) Assignee: Rob Allen (rob) Tags: - Zend_Config

Related issues: Attachments:


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}


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:

<pre class="highlight">
    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?

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

<pre class="highlight">

in UTF-8 on Windows XP using Notepad++. Line endings: [CR][LF].

Content of file.ini:

<pre class="highlight">
environment = development
test = works


<pre class="highlight">
// ś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.'<br></br>';
echo 'Should be "works": '.Zend_Registry::get('configurationSystem')->get('test');

Which displays:

<pre class="highlight">
    [environment] => development
    [test] => works

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

php_info ();

<pre class="highlight">
PHP Version 5.2.5

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 ( 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:

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

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:

<pre class="highlight">
$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

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.

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.