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


PHP A::getClosure方法代码示例

本文整理汇总了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();
开发者ID:badlamer,项目名称:hhvm,代码行数:31,代码来源:closure_041.php

示例2: getClosure

<?php

class A
{
    function getClosure() : Closure
    {
        return function () {
        };
    }
}
$ob1 = new A();
$cl = $ob1->getClosure();
$cl2 = $cl->bindTo(null);
开发者ID:tpunt,项目名称:phan,代码行数:13,代码来源:0154_closure_bindto_accepts_null.php

示例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";
开发者ID:badlamer,项目名称:hhvm,代码行数:20,代码来源:ReflectionFunction_getClosureScopeClass.php

示例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.
开发者ID:badlamer,项目名称:hhvm,代码行数:30,代码来源:closure_037.php

示例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
开发者ID:exakat,项目名称:exakat,代码行数:20,代码来源:ClosureThisSupport.02.php


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