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

Yaf_Config_Ini::offsetGet

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Get a value (ArrayAccess)

Description

Yaf_Config_Ini::offsetGet(mixed $name): mixed

Retrieves a configuration value by key. This method is an alias of Yaf_Config_Ini::get and is called when array syntax is used to read a configuration object.

Parameters

name

The configuration key to retrieve.

Return Values

The value associated with name, or null if the key does not exist.

Examples

Yaf_Config_Ini::offsetGet 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');

echo $config['application.name'], "\n"; // dot notation, as in get()
echo $config['database']['host'], "\n"; // nested access
var_dump($config['cache.enable']);      // missing key
?>

The above example will output something similar to:

output
MyApp
localhost
NULL

See Also

  • Yaf_Config_Ini::get
  • Yaf_Config_Ini::offsetSet
  • Yaf_Config_Ini::offsetUnset

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