php8.5
Home/ Manual/ yaf / yaf_registry/ Yaf_Registry::set

Yaf_Registry::set

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Add an item into registry

Description

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

Stores a value in the registry. Setting an already existing name overwrites its previous value.

Parameters

name

The name of the registry entry.

value

The value to store; it may be of any type, including objects.

Return Values

Returns true on success, or false on failure.

Examples

Yaf_Registry::set example

php
<?php
class Bootstrap extends Yaf_Bootstrap_Abstract
{
    public function _initRedis(Yaf_Dispatcher $dispatcher)
    {
        $config = Yaf_Application::app()->getConfig()->redis;

        $redis = new Redis();
        $redis->connect($config->host, $config->port);

        /* the connection is now available to the whole application */
        Yaf_Registry::set("redis", $redis);
    }
}
?>

See Also

  • Yaf_Registry::get
  • Yaf_Registry::has
  • Yaf_Registry::del

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