php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #28819 parse_ini_file() should look in include_path
Submitted: 2004-06-17 17:49 UTC Modified: 2013-10-28 10:55 UTC
From: kmsluder at optonline dot net Assigned: krakjoe (profile)
Status: Closed Package: *General Issues
PHP Version: 4.3.7 OS: Irrelevant
Private report: No CVE-ID: None
 [2004-06-17 17:49 UTC] kmsluder at optonline dot net
Description:
------------
When keeping include files separate from publicly accessible documents, paths to access files in the includes directory can differ for different pages in the site.  For example, on my setup I keep my site in /var/www; publicly-accessible pages (including my PHP pages) are in /var/www/pub (which is Apache's ServerRoot), and the include file is in /var/www/inc.  Also stored in /var/www/inc are ini files my PHP application uses.  /var/www/inc is in my include_path.

In my PHP pages, I use require('include.inc').  Inside include.inc there are calls to parse_ini_file() to process my ini files.  Since my ini files are stored in the same directory as my include file, I figured at first that referencing them as simple 'config.ini' etc. would work.  Unfortunately, it doesn't, as it looks in the directory of the currently-executing script.  Wouldn't it be more logical for parse_ini_file() to look in include_path instead, considering 1) almost any sane include_path includes ./ anyway, and 2) common sense dictates that ini files should be kept out of the ServerRoot, and it makes sense to put them with the other files that should be kept out of the ServerRoot, your include files?

Reproduce code:
---------------
File: ServerRoot/pub/test.php
=============================
<?php
include('include.inc');
?>

File: ServerRoot/inc/include.inc
================================
<?php
$ini = parse_ini_file('config.ini');
echo $ini['value'];
?>

File: ServerRoot/inc/config.ini
===============================
value=hi

Expected result:
----------------
hi

Actual result:
--------------
Warning: parse_ini_file(): Cannot open 'config.ini' for reading in ServerRoot/include.inc on line 1

Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-18 00:17 UTC] edink@php.net
You can easily do this by:

$ini = parse_ini_file(dirname(__FILE__).'/config.ini');

line in your ServerRoot/inc/include.inc file.

But perhaps it would be a good idea to add an optional parameter to parse_ini_file() to indicate wheather to use include_path.
 [2013-10-28 10:55 UTC] krakjoe@php.net
-Status: Open +Status: Closed -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: krakjoe
 [2013-10-28 10:55 UTC] krakjoe@php.net
This doesn't make good sense.

If we did have that parameter on parse_ini_file, it wouldn't be useful unless it was also on fopen(), unlink(), rename() etc ...

It just doesn't make good sense.

Closing the request.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Aug 17 01:01:29 2024 UTC