本文整理汇总了PHP中A::getClosure方法的典型用法代码示例。如果您正苦于以下问题:PHP A::getClosure方法的具体用法?PHP A::getClosure怎么用?PHP A::getClosure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类A
的用法示例。
在下文中一共展示了A::getClosure方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
$d();
示例2: getClosure
<?php
class A
{
function getClosure() : Closure
{
return function () {
};
}
}
$ob1 = new A();
$cl = $ob1->getClosure();
$cl2 = $cl->bindTo(null);
示例3: function
<?php
$closure = function ($param) {
return "this is a closure";
};
$rf = new ReflectionFunction($closure);
var_dump($rf->getClosureScopeClass());
class A
{
public static function getClosure()
{
return function ($param) {
return "this is a closure";
};
}
}
$closure = A::getClosure();
$rf = new ReflectionFunction($closure);
var_dump($rf->getClosureScopeClass());
echo "Done!\n";
示例4: printX
$this->x++;
self::printX();
self::print42();
static::print42();
};
}
function printX()
{
echo $this->x . "\n";
}
function print42()
{
echo "42\n";
}
}
class B extends A
{
function print42()
{
echo "forty two\n";
}
}
$a = new A();
$closure = $a->getClosure();
$closure();
$b = new B();
$closure = $b->getClosure();
$closure();
?>
Done.
示例5: getClosure
<?php
class A
{
private $value = 1;
public function getClosure()
{
return function () {
return $THIS->value;
};
}
public function dontGetClosure()
{
return $THIS->value;
}
}
$a = new A();
$fn = $a->getClosure();
echo $fn();
// 1