php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #66114 Request to add save_ini_file()
Submitted: 2013-11-18 20:09 UTC Modified: 2019-08-20 20:16 UTC
From: garet at approachfoundation dot org Assigned:
Status: Suspended Package: Filesystem function related
PHP Version: 5.5.6 OS: Any (FreeBSD)
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: garet at approachfoundation dot org
New email:
PHP Version: OS:

 

 [2013-11-18 20:09 UTC] garet at approachfoundation dot org
Description:
------------
---
From manual page: http://www.php.net/function.parse-ini-file
---

Though this is a simple request, I think being able to load and save ini files of this format will increase application portability in the long run for many people. If there were also a way to somewhat augment the parsing schema, to catch other common *nix .conf files, t'would be pretty nice.

Test script:
---------------
<?php

//Load my own configuration file for the user running this app
$ThisAppnConfig = parse_ini_file('~/.MyApplication');

//Load the global configuration for some package used in this app
$SomeAppConfig = parse_ini_file('/etc/SomeApp/default.conf');

$ThisAppConfig['SomeApp.host']=$SomeAppConfig['host']
$SomeAppConfig['host']=$ThisAppConfig['host'];

//Update the user's settings to be compatible with my app
save_ini_file($SomeAppConfig,'~/.SomePackage');

//Save the old value in case the user needs it
save_ini_file($ThisAppConfig,'~/.ThisPackage');

?>

Expected result:
----------------
After loading and parsing two, standard configuration document, the developer uses values and may or may not transfer them to/from other config files with the same format.

At the end, a configuration file is generated from the associative array supplied. 

The only caveat is that on saving, a diff tool should be employed to align any pre-existing key/values to their same line number. By only appending new data to the end, we preserve any user-provided comments as well.

Would also be nice to have similar nesting detection both ways. I,e providing the following..


Array
(
    [first_section] => Array
        (
            [one] => 1
            [five] => 5
            [animal] => Dodo bird
        )

    [second_section] => Array
        (
            [path] => /usr/local/bin
            [URL] => http://www.example.com/~username
        )
)

Works as expected to append/replace within a section before falling back to file append.

Actual result:
--------------
None, feature request.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-02-28 22:17 UTC] cmb@php.net
-Package: Unknown/Other Function +Package: Filesystem function related
 [2019-08-20 20:16 UTC] cmb@php.net
-Status: Open +Status: Suspended
 [2019-08-20 20:16 UTC] cmb@php.net
This feature (request) requires the RFC process[1].  Feel free to
start it anytime!

[1] <https://wiki.php.net/rfc/howto>
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Mar 14 08:01:32 2025 UTC