php8.5
Home/ Manual/ yaf / yaf_config_simple/ Yaf_Config_Simple::__construct

Yaf_Config_Simple::__construct

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Constructor of Yaf_Config_Simple

Description

Yaf_Config_Simple::__construct(array $values, bool $readonly = false)

Creates a new Yaf_Config_Simple instance from an array of configuration values.

Parameters

values

An array of configuration values.

readonly

Whether the configuration should be read-only. Defaults to false (writable).

Return Values

No value is returned.

Examples

Yaf_Config_Simple::__construct example

php
<?php
$config = new Yaf_Config_Simple([
    'application' => ['name' => 'MyApp', 'env' => 'production'],
    'database'    => ['host' => 'localhost', 'port' => 3306],
]);

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

// The optional second argument makes the configuration read-only
$frozen = new Yaf_Config_Simple(['env' => 'testing'], true);
var_dump($frozen->readonly());
?>

The above example will output something similar to:

output
MyApp
localhost
bool(true)

See Also

  • Yaf_Config_Simple::get
  • Yaf_Config_Simple::set
  • Yaf_Config_Simple::readonly

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