当前位置: 首页>>代码示例>>PHP>>正文


PHP A::getStaticClosure方法代码示例

本文整理汇总了PHP中A::getStaticClosure方法的典型用法代码示例。如果您正苦于以下问题:PHP A::getStaticClosure方法的具体用法?PHP A::getStaticClosure怎么用?PHP A::getStaticClosure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在A的用法示例。


在下文中一共展示了A::getStaticClosure方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getStaticClosure

        };
    }
    function getStaticClosure()
    {
        return static function () {
            echo "scoped to A: ";
            var_dump(isset(A::$priv));
            echo "bound: ", isset($this) ? get_class($this) : "no";
        };
    }
}
class B extends A
{
}
$a = new A();
$staticScoped = $a->getStaticClosure();
$nonstaticScoped = $a->getClosure();
echo "Before binding", "\n";
$staticUnscoped();
echo "\n";
$nonstaticUnscoped();
echo "\n";
$staticScoped();
echo "\n";
$nonstaticScoped();
echo "\n";
echo "After binding, no instance", "\n";
$d = $staticUnscoped->bindTo(null);
$d();
echo "\n";
$d = $nonstaticUnscoped->bindTo(null);
开发者ID:badlamer,项目名称:hhvm,代码行数:31,代码来源:closure_041.php

示例2: function

$staticUnscoped = static function () {
    var_dump(isset(A::$priv));
    var_dump(isset($this));
};
class A
{
    private static $priv = 7;
    static function getStaticClosure()
    {
        return static function () {
            var_dump(isset(A::$priv));
            var_dump(isset($this));
        };
    }
}
$staticScoped = A::getStaticClosure();
echo "Before binding", "\n";
$staticUnscoped();
echo "\n";
$staticScoped();
echo "\n";
echo "After binding, null scope, no instance", "\n";
$d = $staticUnscoped->bindTo(null, null);
$d();
echo "\n";
$d = $staticScoped->bindTo(null, null);
$d();
echo "\n";
echo "After binding, null scope, with instance", "\n";
$d = $staticUnscoped->bindTo(new A(), null);
$d();
开发者ID:badlamer,项目名称:hhvm,代码行数:31,代码来源:closure_043.php


注:本文中的A::getStaticClosure方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。