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

Yaf_Config_Simple::offsetSet

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Set a configuration value (ArrayAccess)

Description

Yaf_Config_Simple::offsetSet(mixed $name, mixed $value): void

Sets a configuration value using array syntax. This method is an alias of Yaf_Config_Simple::set. The assignment fails silently if the configuration is read-only.

Parameters

name

The configuration key to set.

value

The value to assign.

Return Values

No value is returned. The assignment fails if the configuration is read-only.

Examples

Yaf_Config_Simple::offsetSet example

php
<?php
$config = new Yaf_Config_Simple(['env' => 'development']);

// Writable by default
$config['env'] = 'production';
$config['cache'] = ['enable' => true];
echo $config['env'], "\n";
var_dump($config['cache']['enable']);

// Assignments to a read-only configuration fail silently
$frozen = new Yaf_Config_Simple(['env' => 'development'], true);
$frozen['env'] = 'production';
echo $frozen['env'], "\n";
?>

The above example will output something similar to:

output
production
bool(true)
development

See Also

  • Yaf_Config_Simple::set
  • Yaf_Config_Simple::offsetGet
  • Yaf_Config_Simple::offsetUnset

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