Industrial Industrial - 1 year ago 85
Ini Question

Losing booleans when parsing *.ini-file using PHP

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

-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:

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
-based configs.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download