Zero-dependency INI configuration file parser and writer for HolyPHP with sections, comments, quoted values, typed getters, and clear line-numbered syntax errors.
bundled — works offlinezero dependenciesconfigsections
Top-level keys (before any [section]) are placed at the root of the returned array.
Section keys are placed in nested associative arrays keyed by section name.
Supports ; and # full-line and inline comments, single-quoted ('...') and double-quoted ("...") strings with escape sequences (\", \\, \n, \r, \t), and CRLF/LF line endings.
ini_stringify(array $data): string
Serializes an associative array back into a formatted INI string.
Automatically quotes and escapes strings containing spaces at the edges, ;, #, =, ", \, or control characters.
Formats booleans as true/false.
Class IniConfig
new IniConfig(array $data = [])
Creates a configuration object from an associative array.
IniConfig::parse(string $content): IniConfig
Parses an INI string and returns a new IniConfig instance.
Returns the boolean value for $key in $section, or $default if not found. Accepts true/false, 1/0, yes/no, on/off (case-insensitive). Throws an Exception if the value is not a valid boolean.
getSection(string $section): array
Returns all key-value pairs in $section (or all global keys when $section === ""). Returns [] if the section does not exist.
has(string $section, string $key): bool
Returns true if $key exists in $section.
hasSection(string $section): bool
Returns true if $section exists.
set(string $section, string $key, $value): void
Sets $key to $value in $section (creating the section if needed). Pass "" for global keys.
stringify(): string
Serializes the configuration to an INI string.
toArray(): array
Returns the underlying associative array.
Error Handling
All syntax and validation errors throw Exception with clear messages prefixed with ini::
ini: unclosed section header on line 3
ini: empty section name on line 2
ini: unexpected characters after section header on line 4
ini: missing '=' in assignment on line 5
ini: empty key in assignment on line 6
ini: unclosed quoted value on line 7
ini: unexpected characters after closing quote on line 8
ini: value for '[database] port' is not a valid integer: 'abc'
ini: value for '[database] ssl' is not a valid boolean: 'maybe'
ini: key cannot be empty
Examples
01Quick start
Bundled with the compiler — import "ini"; works offline in any file, or add it to a project with hphp install ini.