Edit report at https://bugs.php.net/bug.php?id=38409&edit=1
ID: 38409
Updated by: datibbaw@php.net
Reported by: yury at shurup dot com
Summary: parse_ini_file() looses the type of booleans
-Status: Open
+Status: Closed
Type: Feature/Change Request
Package: PHP options/info functions
Operating System: Ubuntu 8.04.1
PHP Version: 5.2.4-2ubuntu5.4 with Suhosin-Patch 0.9.6.2 (cli)
-Assigned To:
+Assigned To: datibbaw
Block user comment: N
Private report: N
New Comment:
The fix for this bug has been committed.
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/.
For Windows:
http://windows.php.net/snapshots/
Thank you for the report, and for helping us make PHP better.
Fixed in repo: http://git.php.net/?p=php-src.git;a=commit;h=5270ee1aef83a4cd17dc1175052ab3b9da94717a
The changes are slated for 5.6.1 onwards.
Previous Comments:
------------------------------------------------------------------------
[2013-12-02 15:25:27] chudinov at yahoo dot com
Versions 5.4 and 5.5 have same problem.
It is quite annoying to cast that is true or false to actually boolean type!
------------------------------------------------------------------------
[2012-03-15 10:17:58] adria dot cidre at gmail dot com
Still not working on Centos over PHP 5.3.10
------------------------------------------------------------------------
[2011-12-19 19:21:23] pwinnski at gmail dot com
PHP 5.3.6 on Centos. Still not fixed, so I must explicitly cast to boolean in the
code that reads the ini file.
------------------------------------------------------------------------
[2010-08-31 23:33:03] guy dot paddock at redbottledesign dot com
Hrm, it also looks like there's a similar problem for integers -- they become integer strings,
so is_int() returns FALSE on them.
Why doesn't parse_ini_file() translate values to the appropriate type?
------------------------------------------------------------------------
[2010-08-31 17:07:06] guy dot paddock at redbottledesign dot com
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?
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=38409
--
Edit this bug report at https://bugs.php.net/bug.php?id=38409&edit=1