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

Yaf_Registry::has

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Check whether an item exists

Description

Yaf_Registry::has(string $name): bool

Checks whether a value exists in the registry.

Parameters

name

The name of the registry entry.

Return Values

Returns true if an entry with the given name exists, false otherwise.

Examples

Yaf_Registry::has example

php
<?php
class Bootstrap extends Yaf_Bootstrap_Abstract
{
    public function _initRedis(Yaf_Dispatcher $dispatcher)
    {
        /* skip the work if a previous bootstrap pass already did it */
        if (Yaf_Registry::has("redis")) {
            return;
        }

        $config = Yaf_Application::app()->getConfig()->redis;

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

        Yaf_Registry::set("redis", $redis);
    }
}
?>

See Also

  • Yaf_Registry::get
  • Yaf_Registry::set
  • Yaf_Registry::del

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