(PHP 5 >= 5.4.0, PHP 7)
Closure::bind — 锟斤拷锟斤拷一锟斤拷锟秸帮拷锟斤拷锟斤拷指锟斤拷锟斤拷$this锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟�
$closure
, object $newthis
[, mixed $newscope
= 'static'
] ) : Closure锟斤拷锟斤拷锟斤拷锟斤拷锟� Closure::bindTo() 锟侥撅拷态锟芥本锟斤拷锟介看锟斤拷锟斤拷锟侥碉拷锟斤拷取锟斤拷锟斤拷锟斤拷息锟斤拷
closure
锟斤拷要锟襟定碉拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷
newthis
锟斤拷要锟襟定碉拷锟斤拷锟斤拷锟斤拷锟斤拷锟侥讹拷锟襟,伙拷锟斤拷
NULL
锟斤拷锟斤拷未锟襟定的闭帮拷锟斤拷
newscope
锟斤拷要锟襟定革拷锟秸帮拷锟斤拷锟斤拷锟斤拷锟斤拷锟津,伙拷锟斤拷 'static' 锟斤拷示锟斤拷锟侥变。锟斤拷锟斤拷锟斤拷锟揭伙拷锟斤拷锟斤拷锟斤拷锟绞癸拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟� 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟节闭帮拷锟斤拷 $this 锟斤拷锟斤拷锟� 私锟叫★拷锟斤拷锟斤拷锟斤拷锟斤拷 锟侥可硷拷锟皆★拷 The class scope to which associate the closure is to be associated, or 'static' to keep the current one. If an object is given, the type of the object will be used instead. This determines the visibility of protected and private methods of the bound object.
锟斤拷锟斤拷一锟斤拷锟铰碉拷 Closure 锟斤拷锟斤拷 锟斤拷锟斤拷锟斤拷失锟斤拷时锟斤拷锟斤拷 FALSE
Example #1 Closure::bind() 实锟斤拷
<?php
class A {
private static $sfoo = 1;
private $ifoo = 2;
}
$cl1 = static function() {
return A::$sfoo;
};
$cl2 = function() {
return $this->ifoo;
};
$bcl1 = Closure::bind($cl1, null, 'A');
$bcl2 = Closure::bind($cl2, new A(), 'A');
echo $bcl1(), "\n";
echo $bcl2(), "\n";
?>
锟斤拷锟斤拷锟斤拷锟教碉拷锟斤拷锟斤拷锟斤拷锟斤拷冢锟�
1 2