ID:               38409
 User updated by:  yury at shurup dot com
 Reported By:      yury at shurup dot com
 Status:           Open
 Bug Type:         Feature/Change Request
-Operating System: Windows 2000 SP4 Rollup 2
+Operating System: Ubuntu 8.04.1
-PHP Version:      4.4.3
+PHP Version:      5.2.4-2ubuntu5.4 with Suhosin-Patch 0.9.6.2 (cli)
 New Comment:

It is very sad that this bug is still not classified, fixed and is
perfectly reproducible after about 2 years since my original posting. I
hope I would be able to hack on the sources some day but surely not
during the next year to come.


Previous Comments:
------------------------------------------------------------------------

[2008-12-12 13:14:15] philipp dot kempgen at amooma dot de

In addition to that I want NULL (unquoted) to be of type NULL.
Unquoted integers => int, unquoted floating point numbers =>
float/double.

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

[2008-12-12 13:04:57] philipp dot kempgen at amooma dot de

Same problem on Linux and PHP 5(.1).

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

[2006-08-10 10:42:58] yury at shurup dot com

Description:
------------
Hi!

I have searched a bug database for the parse_ini_file keyword, but
didn't find a releavant report submitted earlier. I am aware of bugs

http://bugs.php.net/bug.php?id=18411
http://bugs.php.net/bug.php?id=19575

but I am asking for another thing.

The problem is that in the described environment, PHP's
parse_ini_file() function looses the type record for booleans and
qualifies them either as an empty string for "false" or 1-char string
(containing "1") for "true" instead of qualifying them as booleans as it
is supposed to be (no relevant docs on this behaviour as well). 

If this is by design, then IMHO it is absolutely a subject to change
and document in future PHP versions, because, YES, you can cast the type
from string to bool, BUT what if you don't know that it IS a bool
(parsing an abstract INI file)? 

After all, originally those INI-files came from Windows and everybody
should treat them similar to the GetProfile... functions to avoid
confusion (an unquoted boolean keyword like in the example below should
remain a boolean, while quoted keyword should be treated as a string).
In any case it wouldn't hurt and cause incompatibilies with older
versions.

This is very annoying for someone writing a non-intrusive INI-file
parser (which, e.g. would preserve comments, thus operating with
parse_ini_file to read and the regular expressions to write out).

Reproduce code:
---------------
Script
======

$stuff = parse_ini_file($file, true);
var_dump($stuff);

$a = array();
$a["foo"] = true;
$a["bar"] = false;
var_dump($a);

INI file
========

[foo]
bar = false
quux = true

Expected result:
----------------
["bar"]=> bool(false)
["quux"]=> bool(true)

array(2) {
  ["foo"]=> bool(true)
  ["bar"]=> bool(false)
}

Actual result:
--------------
["bar"]=>  string(0) ""
["quux"]=>  string(1) "1"

array(2) {
  ["foo"]=> bool(true)
  ["bar"]=> bool(false)
}


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


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

Reply via email to