Edit report at http://bugs.php.net/bug.php?id=38409&edit=1
ID: 38409 Comment by: guy dot paddock at redbottledesign dot com Reported by: yury at shurup dot com Summary: parse_ini_file() looses the type of booleans Status: Open Type: Feature/Change Request Package: Feature/Change Request Operating System: Ubuntu 8.04.1 PHP Version: 5.2.4-2ubuntu5.4 with Suhosin-Patch 0.9.6.2 (cli) Block user comment: N New Comment: I also second the fact that parse_ini_file() should parse booleans as boolean types, rather than strings. In my application, the values returned from parsing the INI file are checked to ensure that they are the correct type (string, bool, int, etc). That way, if the user accidentally typed the wrong value in for a setting, they are presented with the appropriate error message, rather than having their value interpreted incorrectly. Unfortunately, the way that parse_ini_file() parses booleans, it converts "TRUE" and "FALSE" into "1" or an empty string "", which means that is_bool() returns FALSE. I understand perfectly that is_bool() is intended only to determine if a variable really is a boolean -- my problem is not with that function. My problem is with parse_ini_file()'s counter-intuitive behavior of not parsing boolean values into a boolean type. Why else would we want it interpreting boolean constants in the first place? Previous Comments: ------------------------------------------------------------------------ [2008-12-12 14:43:42] yury at shurup dot com 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. ------------------------------------------------------------------------ [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/bug.php?id=38409&edit=1