php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #67331 Have parse_ini_file add empty entries
Submitted: 2014-05-22 22:27 UTC Modified: 2018-09-15 15:26 UTC
From: philip@php.net Assigned:
Status: Re-Opened Package: *Configuration Issues
PHP Version: 5.6.0beta3 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: philip@php.net
New email:
PHP Version: OS:

 

 [2014-05-22 22:27 UTC] philip@php.net
Description:
------------
MySQL has options (such as "no-auto-rehash") in my.cnf that do not take values. In this case, it's one of the following:

no-auto-rehash
auto-rehash

The parse_ini_* functions ignore these, as they lack an "=".


Test script:
---------------
philip$ php -r '$s = "foo = bar\nauto-rehash\nbaz ="; var_dump(parse_ini_string($s));'


Expected result:
----------------
array(3) {
  ["foo"]=>
  string(3) "bar"
  ["auto-refresh"]=>
  string(0) ""
  ["baz"]=>
  string(0) ""
}

Actual result:
--------------
array(2) {
  ["foo"]=>
  string(3) "bar"
  ["baz"]=>
  string(0) ""
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-05-23 02:39 UTC] philip@php.net
Johannes pointed out another example. Python allows the "No value" style, as documented here:

https://docs.python.org/3/library/configparser.html#supported-ini-file-structure

Also, assigned value for these is worth discussing, as perhaps no value entries should be defined as NULL instead of ""? In that case, the expected results would be:

array(3) {
  ["foo"]=>
  string(3) "bar"
  ["auto-refresh"]=>
  NULL
  ["baz"]=>
  string(0) ""
}
 [2014-05-23 03:53 UTC] aharvey@php.net
I spiked a quick patch for this: https://github.com/LawnGnome/php-src/compare/php:93a98202d0e8d0f2bfdf4392a4baf2301e343985...bug67331?expand=1

There's one issue, though, which causes the new test to fail: a bare option on the last line of input isn't parsed. This appears to be an issue somewhere in the lexer and/or parser, as the callback is never called to process the input, but my lexer/parser-fu is not good enough to discern why. Help is needed!

Beyond that, we'd have to figure out if we would need to hide this behind an option, given potential BC concerns, although my feeling is that this is safe enough for master.
 [2014-06-16 14:12 UTC] felipe@php.net
You just missed a simple change:

-LABEL [^=\n\r\t;|&$~(){}!"\[]+
+LABEL [^=\n\r\t;|&$~(){}!"\[\000]+
 [2014-07-03 23:10 UTC] philip@php.net
Automatic comment from SVN on behalf of philip
Revision: http://svn.php.net/viewvc/?view=revision&revision=334105
Log: Mention that entries without an equal sign are ignored. Recent feature request PHP Bug #67331 requests this functionality.
 [2018-08-28 15:39 UTC] cmb@php.net
<https://github.com/php/php-src/pull/3473> submitted.
 [2018-09-15 14:01 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2018-09-15 14:01 UTC] cmb@php.net
The PR has been applied[1] – closing.

[1] <http://git.php.net/?p=php-src.git;a=commit;h=3f3e914df33793a36f51b4e44745d6a5aec4f685>
 [2018-09-15 14:05 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=345642
Log: Update regarding implemented feature request #67331
 [2018-09-15 15:12 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=345643
Log: Revert revision(s) 345642 from phpdoc/en/trunk:
Update regarding implemented feature request #67331
 [2018-09-15 15:26 UTC] cmb@php.net
-Status: Closed +Status: Re-Opened
 [2018-09-15 15:26 UTC] cmb@php.net
I have reverted the commit for now, since it broke some tests on
Windows. Strangely, these tests appear to succeed on Linux.
Anyhow, changing the NULL to an empty string lets the tests
succeed on Windows. Considering strict typing, setting entries
without equal sign to an empty string might be better anyway
(that's also done this way by Python).  

But there are more issues.  Firstly, run-tests.php is not prepared
for entries without equal sign[1].  Secondly, the `-d` option of
the CLI php (I have not yet checked other SAPIs) seems to
interpret options without equal sign as enabling them[2], which
would be inconsistent.  Changing this, however, would be a
considerable BC break.

[1] <https://github.com/php/php-src/blob/php-7.3.0RC1/run-tests.php#L2378-L2395>
[2] <https://github.com/php/php-src/blob/php-7.3.0RC1/sapi/cli/php_cli.c#L1303-L1308>
 [2018-09-15 15:26 UTC] cmb@php.net
-Assigned To: cmb +Assigned To:
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Jul 23 13:01:26 2019 UTC