php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44019 Quoted strings in parse_ini_file function are not handled properly
Submitted: 2008-02-01 23:15 UTC Modified: 2008-02-04 20:45 UTC
From: petr at hroch dot info Assigned: jani (profile)
Status: Closed Package: Filesystem function related
PHP Version: 5.3CVS-2008-02-01 (snap) OS: *
Private report: No CVE-ID: None
 [2008-02-01 23:15 UTC] petr at hroch dot info
Description:
------------
Quoted strings in parse_ini_file function are not handled properly
Tested on Windows XP SP2 php5.3-dev running as apache 2.2.6 module
possibly not working on the other operation systems
I've searched the web
and I've found the same problem already described php6.0-dev snapshot http://groups.google.pl/group/mailing.www.php-dev/msg/e5b4b179d4d3ce15


Reproduce code:
---------------
Ini file test.ini content:
--------------------------

[Topic]
number=1
string="test"
foo=FOO"barian"

PHP code test.php:
------------------

<?
define("FOO","bar");
print_r(parse_ini_file("test.ini",true));
?>

Expected result:
----------------
Array
(
    [Topic] => Array
        (
            [number] => 1
            [string] => test
            [foo] => barbarian
        )

)

Actual result:
--------------
Warning: syntax error, unexpected TC_QUOTED_STRING in test.ini on line 3 in D:\htdocs\test.php on line 3
Array ( )

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-02-02 20:22 UTC] jani@php.net
Where did you get the idea that that should work in the first place?
The correct way:

foo="{$FOO}barian"
 [2008-02-03 15:26 UTC] petr at hroch dot info
Hello Jani,

Before I've submited this bug, I've tested this feature in php-5.2.5
where line foo=FOO"barian" returns [foo] => barbarian
so it works gracefully, in php5.3-dev it doesn't.

In my example FOO is a constant defined before parse_ini_file function.
In your example $FOO is undefined global variable isn't it?
Anyway changing ini file using your way doesn't work as expected, even
if there's no $FOO definition I should be expecting that
foo="{$FOO}barian"  returns [foo] => barian                          
                        not [foo] => FOO}barian

modified Test.ini using Jani's solution
-------------------------------------
[Topic]
number=1
string="test"
foo="{$FOO}barian"

PHP code:
--------
<?
define("FOO","bar");
print_r(parse_ini_file("test.ini",true));
?>

Expected result:
----------------
Array
(
    [Topic] => Array
        (
            [number] => 1
            [string] => test
            [foo] => barbarian
        )

)
Actual Result:
--------------
Array
(
    [Topic] => Array
        (
            [number] => 1
            [string] => test
            [foo] => FOO}barian
        )

)

I Hope it helps.
Best regards
Petr
 [2008-02-04 10:48 UTC] jani@php.net
Ah, now I see. I didn't have any machine to test with during the weekend so I got it wrong way. :D

In 5.3 the ini parsing has been improved, and along the line I broke some old stuff which I actually didn't think anyone relied upon.

I have to investigate and check if it's possible even to keep this old (and bad) syntax. Is it even documented anywhere?
 [2008-02-04 11:54 UTC] petr at hroch dot info
I've used this syntax in 5.x versions till now.
I got most suggestions and ideas from official documentation and comment discussion http://php.net/manual/en/function.parse-ini-file.php
Maybe it's good idea to post there the new syntax usage change for versions >= 5.3
before it's officially changed in documentation on php5.3 stable release.

Regards
Petr
 [2008-02-04 20:33 UTC] jani@php.net
Hold your horses, I have a fix already, just waiting for commit..
 [2008-02-04 20:33 UTC] jani@php.net
And btw. Comments in the manual are not documented behaviour. :)
 [2008-02-04 20:45 UTC] jani@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 18:01:28 2024 UTC