array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'tr', ), 'this' => array ( 0 => 'closure.bind.php', 1 => 'Closure::bind', ), 'up' => array ( 0 => 'class.closure.php', 1 => 'Closure', ), 'prev' => array ( 0 => 'closure.construct.php', 1 => 'Closure::__construct', ), 'next' => array ( 0 => 'closure.bindto.php', 1 => 'Closure::bindTo', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'tr', 'path' => 'language/predefined/closure/bind.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5 >= 5.4.0, PHP 7, PHP 8)
Closure::bind — Belli bir bağlı nesne ve sınıf bağlamıyla bir closure nesnesini kopyalar.
$closure
, ?object $newThis
, object|string|null $newScope
= "static"): ?ClosureBu yöntem Closure::bindTo() yönteminin statik sürümüdür. Daha fazla bilgi için bu yöntemin belgesine bakınız.
closure
Bağlanacak anonim işlevin adı.
newThis
Anonim işleve bağlaması için verilen nesne ya da
bağın kaldırılması için null
.
newScope
İlişkili closure'un ilişkilendirileceği sınıf bağlamı ya da ilişkili olanı tutmak için 'static'. Bir nesne belirtilirse bu nesnenin sınıfı geçerli olur. Bu, bağlı nesnenin protected ve private yöntemlerinin görünürlüğünü saptamaya yarar. Bu bağımsız değişkende dahili bir sınıfı (nesnesini) aktarmaya izin verilmez.
Örnek 1 - Closure::bind() örneği
<?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";
?>
Yukarıdaki örnek şuna benzer bir çıktı üretir:
1 2