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

Yaf_Config_Ini::get

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Retrieve a configuration value

Description

Yaf_Config_Ini::get(string $name = NULL): mixed

Retrieves a configuration value by name. Dot notation (e.g. database.host) can be used to access nested values. If name is omitted or null, the configuration object itself is returned.

Parameters

name

The configuration key, optionally using dot notation for nested access.

Return Values

The value associated with name. Array values are wrapped in a Yaf_Config_Ini object. Returns null if the key does not exist, or the configuration object itself when name is null.

Examples

Yaf_Config_Ini::get example

php
<?php
/**
 * Assume /etc/myapp/application.ini contains:
 * [common]
 * application.name = "MyApp"
 * database.host    = "localhost"
 * database.port    = 3306
 */
$config = new Yaf_Config_Ini('/etc/myapp/application.ini', 'common');

// Dot notation for nested access
echo $config->get('database.host'), "\n";

// Array values are wrapped in a Yaf_Config_Ini object
echo $config->get('database')->port, "\n";

// No argument: the configuration object itself is returned
echo $config->get()->application->name, "\n";

var_dump($config->get('missing.key'));
?>

The above example will output something similar to:

output
localhost
3306
MyApp
NULL

See Also

  • Yaf_Config_Ini::set
  • Yaf_Config_Ini::toArray

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