|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-09-02 15:52 UTC] eric dot caron at gmail dot com
Description:
------------
PHP 5.3 changes to parse_ini_*() functions breaks scripts that have special characters, {}|&~![()^", in the section titles. (Previous versions worked, which I assume was proper behavior because section titles can have those characters according to community understood INI standards).
There is no documentation stating that special characters can not be used in section titles. While the INI_SCANNER_RAW parameter provides an opening for a workaround for this solution, to be useful, the characters {}|&~![()^" should be usable in section titles (not to be confuse with keys, where they shouldn't be used).
Reproduce code:
---------------
<?php
$tmpfname = tempnam("/tmp", "FOO");
file_put_contents($tmpfname, '[Ask]
Crawler=true
[Mozilla/?.0 (compatible; Ask Jeeves/Teoma*)]
Crawler=true
');
$array = parse_ini_file($tmpfname, true);
print_r($array);
unlink($tmpfname);
Expected result:
----------------
Array
(
[Ask] => Array
(
[Crawler] => 1
)
[Mozilla/?.0 (compatible; Ask Jeeves/Teoma*)] => Array
(
[Crawler] => 1
)
)
Actual result:
--------------
Warning: parse error, expecting `']'' in FOOFCCA.tmp on line 4 in parseBug.php on line 10
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 08:00:01 2025 UTC |
The raw option, though, does not convert the string "true"/"false" to its boolean. If you change the print_r in my demo code to a var_dump: *** PHP 5.2 RESULTS *** array(2) { ["Ask"]=> array(1) { ["Crawler"]=> string(1) "1" } ["Mozilla/?.0 (compatible; Ask Jeeves/Teoma*)"]=> array(1) { ["Crawler"]=> string(1) "1" } } *** PHP 5.3 RESULTS *** array(2) { ["Ask"]=> array(1) { ["Crawler"]=> string(4) "true" } ["Mozilla/?.0 (compatible; Ask Jeeves/Teoma*)"]=> array(1) { ["Crawler"]=> string(4) "true" } }The logic difficulty is better showcased with "false" values. *** PHP 5.2 (GOOD) *** array(2) { ["Ask"]=> array(1) { ["Crawler"]=> string(0) "" } ["Mozilla/?.0 (compatible; Ask Jeeves/Teoma*)"]=> array(1) { ["Crawler"]=> string(1) "1" } } *** PHP 5.3 (BAD) *** array(2) { ["Ask"]=> array(1) { ["Crawler"]=> string(5) "false" } ["Mozilla/?.0 (compatible; Ask Jeeves/Teoma*)"]=> array(1) { ["Crawler"]=> string(4) "true" } }