var_dump($cl1, $cl1 instanceof Closure, $bCl1(), $bCl2());
echo '<hr />';
class B
{
    function __construct($val)
    {
        $this->val = $val;
    }
    function getClosure()
    {
        return function () {
            return $this->val;
        };
    }
    function val()
    {
        return $this->val;
    }
}
$obj1 = new B(1);
$obj2 = new B(2);
$cl = $obj1->getClosure();
var_dump($obj1->val(), $cl());
$cl = $cl->bindTo($obj2);
var_dump($obj2->val(), $cl());
echo '<hr />';
$fn = function () {
    return ++$this->val;
};
$fn = $fn->bindTo($obj2);
var_dump($obj2->val(), $fn(), $obj2->val());
示例#2
0
            $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.