Industrial Industrial - 1 month ago 9
Ini Question

Losing booleans when parsing *.ini-file using PHP

Just tried to make my own config handler in PHP, utilizing the native PHP

parse_ini_file
-function. I did just notice that all of my config entries where the value is a boolean - true/false are messed up, along with most other config entries being typecasted to strings.

Apparently, this is a well-known issue already: http://www.php.net/manual/en/function.parse-ini-file.php#100851

So what is the appropriate workaround?

It's really neat to utilize non-PHP-configs, which makes it dead easy for non-developers to change a value when necessary, so I would love to keep the
*.ini
-based configs.

Answer

I guess the most simple solution to the problem is to just use your own config handler. Either write a ini class or download a free one (ini format is extremely simple).

But I would recommend storing your config in xml if you want interoperability. Every modern programming language has tons of XML parsers available or build-in. Also you gain more flexibility in your settings structure. And you can easily make you settings format typesafe.