|  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: Assigned:
Status: Re-Opened Package: *Configuration Issues
PHP Version: 5.6.0beta3 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2014-05-22 22:27 UTC]
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:


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) {
  string(3) "bar"
  string(0) ""
  string(0) ""

Actual result:
array(2) {
  string(3) "bar"
  string(0) ""


Add a Patch

Pull Requests

Add a Pull Request


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

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) {
  string(3) "bar"
  string(0) ""
 [2014-05-23 03:53 UTC]
I spiked a quick patch for this:

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]
You just missed a simple change:

-LABEL [^=\n\r\t;|&$~(){}!"\[]+
+LABEL [^=\n\r\t;|&$~(){}!"\[\000]+
 [2014-07-03 23:10 UTC]
Automatic comment from SVN on behalf of philip
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]
<> submitted.
 [2018-09-15 14:01 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2018-09-15 14:01 UTC]
The PR has been applied[1] – closing.

[1] <;a=commit;h=3f3e914df33793a36f51b4e44745d6a5aec4f685>
 [2018-09-15 14:05 UTC]
Automatic comment from SVN on behalf of cmb
Log: Update regarding implemented feature request #67331
 [2018-09-15 15:12 UTC]
Automatic comment from SVN on behalf of cmb
Log: Revert revision(s) 345642 from phpdoc/en/trunk:
Update regarding implemented feature request #67331
 [2018-09-15 15:26 UTC]
-Status: Closed +Status: Re-Opened
 [2018-09-15 15:26 UTC]
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] <>
[2] <>
 [2018-09-15 15:26 UTC]
-Assigned To: cmb +Assigned To:
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jun 21 01:01:29 2024 UTC