本文整理汇总了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);
示例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();