From: bugs at timj dot co dot uk
Operating system: irrelevant
PHP version: 5.2.6
PHP Bug Type: Filesystem function related
Bug description: Design problem: parse_ini_file lacks ability to handle errors
gracefully
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
--
Edit bug report at http://bugs.php.net/?id=45956&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=45956&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=45956&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=45956&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=45956&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=45956&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=45956&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=45956&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=45956&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=45956&r=support
Expected behavior: http://bugs.php.net/fix.php?id=45956&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=45956&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=45956&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=45956&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=45956&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=45956&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=45956&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=45956&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=45956&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=45956&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=45956&r=mysqlcfg