php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #72578 parse_ini_string() doesn't store extension/zend_extension entries correctly
Submitted: 2016-07-11 19:12 UTC Modified: 2016-07-11 21:40 UTC
From: kurt dot newman at cpanel dot net Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 7.0.8 OS: Linux
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: kurt dot newman at cpanel dot net
New email:
PHP Version: OS:

 

 [2016-07-11 19:12 UTC] kurt dot newman at cpanel dot net
Description:
------------
---
From manual page: http://www.php.net/function.parse-ini-string
---

This impacts PHP versions: 5.4.45, 5.5.37, 5.6.23, and 7.0.8.

The documentation does not say that ini entries will be missing and should be considered a bug.  The documentation says:

   parse_ini_string() returns the settings in string ini in an associative array.


As such, this function doesn't properly parse a PHP ini string AND return the complete settings described in said string within a resulting associative array.

Test script:
---------------
<?php
    # How to duplicate
    # echo -e "extension = foo.so\nextension = bar.so\n" > foo.ini
    # cat foo.ini | ./thisscript.php

    $ini   = "";
    $stdin = fopen('php://stdin', 'r');

    while (($line = fgets($stdin)) != false)
        $ini .= $line;

    fclose($stdin);

    if (!($arr = parse_ini_string($ini, true, INI_SCANNER_RAW))) {
        fwrite(STDERR, "ERROR: Invalid php ini format\n");
        exit(1);
    }

    print_r( $arr );

    exit(0);
?>

Expected result:
----------------
Recognize that the 'extension' and 'zend_extension' ini entries are special, and can be duplicated within an ini file.  Perhaps consider placing them in some special place so that this information isn't lost.

This is just an example, and not a request to use this specific output:

Array
(
   [extension] => Array
       (
          [extension0] => foo.so
          [extension1] => bar.so
       )
)

Actual result:
--------------
# Observe that "foo.so" was defined in the example noted in
# the 'Test script', but is missing in the actual usage.

Array
(
    [extension] => bar.so
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-07-11 19:36 UTC] requinix@php.net
-Type: Bug +Type: Feature/Change Request -Package: Unknown/Other Function +Package: Filesystem function related
 [2016-07-11 19:36 UTC] requinix@php.net
Your repro script is far more complicated than it needs to be...
  print_r(parse_ini_string("extension = foo.so\nextension = bar.so"));

php.ini is the weird one here, using duplicate names for loading extensions. Highly unusual for an INI file - but its reason for doing so makes sense. parse_ini_string is handling the duplicates the same way that nearly every other INI scanner out there does: overwrite.

So really what you're asking for is an option to allow duplicates, right? To put multiple values into an array (wouldn't be that name+counter format) without having to use the [] syntax.
 [2016-07-11 20:33 UTC] kurt dot newman at cpanel dot net
First, the original example is nothing but a copy & paste from a script that does a lot more than just what I pasted here.

Second, I’m not trying to dictate the “how it should be implemented” portion.  I’d prefer to leave that up to the PHP developers to decide.

What I am asking, is that when I call parse_ini_string(), that it returns all of the information it parsed as documented.
 [2016-07-11 20:56 UTC] requinix@php.net
It is working as documented: it's putting the key/value pairs into an associative array. And like with all associative arrays throughout the rest of PHP, duplicate keys are not allowed and will overwrite each other.

Okay... So are you saying you want a note/warning on the parse_ini_string|file pages pointing out that they don't support duplicate keys unless the array syntax is used?
 [2016-07-11 21:03 UTC] kurt dot newman at cpanel dot net
You know? To make this easier for myself, instead of the PHP developer community, I'll just use a myriad ini parsers out there (or write my own) and move on.

What I was hoping for was a developer who was more interested in solving a bug in the API instead of mincing words and reclassifying an obvious issue as a feature request.  This feels more like a defensive mechanism, and instead of working to come to a solution.

The documentation clearly states that it returns the settings in the ini string.  The fact that it does not return all settings is a BUG.  The underlying issue is that the data structure used clobbers previously defined settings.
 [2016-07-11 21:40 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2016-07-11 21:40 UTC] requinix@php.net
The current behavior is not a bug and I tried to offer you alternatives. Sorry that you were offended by it.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 22:01:30 2024 UTC