php8.5
Home/ Manual/ yaf / yaf_config_ini/ Yaf_Config_Ini::__construct

Yaf_Config_Ini::__construct

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Constructor of Yaf_Config_Ini

Description

Yaf_Config_Ini::__construct(mixed $config_file, string $section = NULL)

Creates a new Yaf_Config_Ini instance from an INI file or an array. The resulting configuration is always read-only.

Parameters

config_file

The path to an INI file, or an array of configuration values.

section

The INI section name to load. If omitted, all sections are loaded.

Return Values

No value is returned.

Examples

Yaf_Config_Ini::__construct example

php
<?php
/**
 * Assume /etc/myapp/application.ini contains:
 * [common]
 * application.name = "MyApp"
 * database.host    = "localhost"
 * database.port    = 3306
 *
 * [production : common]
 * log.level        = "warning"
 */

// Load only the "production" section, which inherits from "common"
$config = new Yaf_Config_Ini('/etc/myapp/application.ini', 'production');

echo $config->application->name, "\n";
echo $config->database->host, "\n";
echo $config->log->level, "\n";
?>

The above example will output something similar to:

output
MyApp
localhost
warning

See Also

  • Yaf_Config_Ini::get
  • Yaf_Config_Ini::set
  • Yaf_Config_Ini::readonly

Source: reference/yaf/yaf_config_ini/construct.xml · from the official PHP manual (php/doc-en)