PHP 8.6.0 Beta 3 is available for testing

Yaf_Registry::has

(Yaf >=1.0.0)

Yaf_Registry::has检测条目是否存在

说明

public static function Yaf_Registry::has(string $name): bool

检测注册表中是否存在某个值。

参数

name

注册表条目的名称。

返回值

如果存在给定名称的条目,则返回 true,否则返回 false

示例

示例 #1 Yaf_Registry::has() 示例

<?php
class Bootstrap extends Yaf_Bootstrap_Abstract
{
    public function _initRedis(Yaf_Dispatcher $dispatcher)
    {
        /* 如果之前的引导过程已经完成了这项工作,就跳过 */
        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);
    }
}
?>

参见

添加备注

用户贡献的备注

此页面尚无用户贡献的备注。
To Top