web.onassar.com Archive

I can be reached at onassar@gmail.com.

For my open source work, check out github.com/onassar

PHP: Accessing constants in INI files

View more posts

I use INI files heavily in my apps, generally to setup configuration files that are processed/run at runtime. They store really general, all-purpose data such as ini-values, paths to certain files, or error message controls.

When storing paths to other files though, I thought it'd be useful if I could reference constants, since paths are normally only useful in the context of other system/application paths.

The process was actually pretty simple. I simply prepended the constant (haven't tried appending) to the string value itself, like so:


When I run the parse_ini_file function on this file, the error_log value will be calculated to have the APP PHP-constant prepended to it.

I'm not sure if there are any significant performance-issues with this, but it works well for what I need, and makes my code cleaner all in one :)