Req #72578 [Com]: parse_ini_string() doesn't store extension/zend_extension entries correctly

From: Date: Mon, 11 Jul 2016 21:03:37 +0000
Subject: Req #72578 [Com]: parse_ini_string() doesn't store extension/zend_extension entries correctly
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-202217@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72578&edit=1

 ID:                 72578
 Comment by:         kurt dot newman at cpanel dot net
 Reported by:        kurt dot newman at cpanel dot net
 Summary:            parse_ini_string() doesn't store
                     extension/zend_extension entries correctly
 Status:             Open
 Type:               Feature/Change Request
 Package:            Filesystem function related
 Operating System:   Linux
 PHP Version:        7.0.8
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2016-07-11 20:56:07] 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 20:33:51] 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 19:36:03] 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 19:12:46] 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
)


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=72578&edit=1


Thread (6 messages)

« previous php.bugs (#202217) next »