php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45956 parse_ini_file() does not return false with syntax errors in parsed file
Submitted: 2008-08-30 18:59 UTC Modified: 2008-08-31 00:21 UTC
From: bugs at timj dot co dot uk Assigned: jani (profile)
Status: Closed Package: Filesystem function related
PHP Version: 5CVS, 6CVS (2008-08-31) OS: *
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: bugs at timj dot co dot uk
New email:
PHP Version: OS:

 

 [2008-08-30 18:59 UTC] bugs at timj dot co dot uk
Description:
------------
This seems to be a design error rather than a bug: parse_ini_file() does not provide any way to handle errors gracefully. In the event of a syntax error, it throws an E_WARNING *but* the return value is simply an empty array (the same as a - valid - empty file) instead of FALSE. Thus there is no way to trap the error (via @ prefix) and handle it in a more graceful way than an E_WARNING.

I would argue that changing the return value to FALSE in the case of an invalid file is a reasonable change, since the only situations it will break are ones where currently PHP throws a warning anyway.


Reproduce code:
---------------
This is what it would be nice to be able to do:

$ini = @parse_ini_file('some_invalid.ini');
if ($ini === false) {
   // error: do something graceful
}
// normal execution

Expected result:
----------------
The code section "// do something graceful" executes

Actual result:
--------------
The code section "// normal execution" executes

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-30 22:41 UTC] jani@php.net
It's a bug. Oversight, but bug nevertheless.
 [2008-08-31 00:21 UTC] jani@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 12:01:29 2024 UTC