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

Yaf_Config_Simple::set

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Set a configuration value

Description

Yaf_Config_Simple::set(string $name, mixed $value): bool

Sets a configuration value. Fails and returns false if the configuration is read-only.

Parameters

name

The configuration key to set.

value

The value to assign.

Return Values

Returns true on success, or false if the configuration is read-only.

Examples

Yaf_Config_Simple::set example

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

var_dump($config->set('env', 'production'));
echo $config->env, "\n";

// Read-only configurations reject the modification
$frozen = new Yaf_Config_Simple(['env' => 'development'], true);
var_dump($frozen->set('env', 'production'));
echo $frozen->env, "\n";
?>

The above example will output something similar to:

output
bool(true)
production
bool(false)
development

See Also

  • Yaf_Config_Simple::get
  • Yaf_Config_Simple::readonly

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