<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.closure.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'closure.bind.php',
    1 => 'Closure::bind',
    2 => 'Duplicates a closure with a specific bound object and class scope',
  ),
  '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' => 'en',
    'path' => 'language/predefined/closure/bind.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="closure.bind" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Closure::bind</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.4.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">Closure::bind</span> &mdash; <span class="dc-title">
   Duplicates a closure with a specific bound object and class scope
  </span></p>

 </div>

 <div class="refsect1 description" id="refsect1-closure.bind-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><strong>Closure::bind</strong></span>(<span class="methodparam"><span class="type"><a href="class.closure.php" class="type Closure">Closure</a></span> <code class="parameter">$closure</code></span>, <span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.object.php" class="type object">object</a></span></span> <code class="parameter">$newThis</code></span>, <span class="methodparam"><span class="type"><span class="type"><a href="language.types.object.php" class="type object">object</a></span>|<span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.null.php" class="type null">null</a></span></span> <code class="parameter">$newScope</code><span class="initializer"> = &quot;static&quot;</span></span>): <span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="class.closure.php" class="type Closure">Closure</a></span></span></div>

  <p class="para rdfs-comment">
   This method is a static version of <span class="methodname"><a href="closure.bindto.php" class="methodname">Closure::bindTo()</a></span>.
   See the documentation of that method for more information.
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-closure.bind-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <dl>
   
    <dt><code class="parameter">closure</code></dt>
    <dd>
     <p class="para">
      The anonymous functions to bind.
     </p>
    </dd>
   
   
    <dt><code class="parameter">newThis</code></dt>
    <dd>
     <p class="para">
      The object to which the given anonymous function should be bound, or
      <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> for the closure to be unbound.
     </p>
    </dd>
   
   
    <dt><code class="parameter">newScope</code></dt>
    <dd>
     <p class="para">
      The class scope to which the closure is to be associated, or
      &#039;static&#039; 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.
      It is not allowed to pass (an object of) an internal class as this parameter.
     </p>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-closure.bind-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="para">
   Returns a new <span class="classname"><a href="class.closure.php" class="classname">Closure</a></span> object, or <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> on failure.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-closure.bind-examples">
  <h3 class="title">Esempi</h3>
  <div class="example" id="example-1">
   <p><strong>Example #1 <span class="function"><strong>Closure::bind()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class </span><span style="color: #0000BB">A </span><span style="color: #007700">{<br />    private static </span><span style="color: #0000BB">$sfoo </span><span style="color: #007700">= </span><span style="color: #0000BB">1</span><span style="color: #007700">;<br />    private </span><span style="color: #0000BB">$ifoo </span><span style="color: #007700">= </span><span style="color: #0000BB">2</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">$cl1 </span><span style="color: #007700">= static function() {<br />    return </span><span style="color: #0000BB">A</span><span style="color: #007700">::</span><span style="color: #0000BB">$sfoo</span><span style="color: #007700">;<br />};<br /></span><span style="color: #0000BB">$cl2 </span><span style="color: #007700">= function() {<br />    return </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">ifoo</span><span style="color: #007700">;<br />};<br /><br /></span><span style="color: #0000BB">$bcl1 </span><span style="color: #007700">= </span><span style="color: #0000BB">Closure</span><span style="color: #007700">::</span><span style="color: #0000BB">bind</span><span style="color: #007700">(</span><span style="color: #0000BB">$cl1</span><span style="color: #007700">, </span><span style="color: #0000BB">null</span><span style="color: #007700">, </span><span style="color: #DD0000">'A'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$bcl2 </span><span style="color: #007700">= </span><span style="color: #0000BB">Closure</span><span style="color: #007700">::</span><span style="color: #0000BB">bind</span><span style="color: #007700">(</span><span style="color: #0000BB">$cl2</span><span style="color: #007700">, new </span><span style="color: #0000BB">A</span><span style="color: #007700">(), </span><span style="color: #DD0000">'A'</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$bcl1</span><span style="color: #007700">(), </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">$bcl2</span><span style="color: #007700">(), </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>Il precedente esempio visualizzerà
qualcosa simile a:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">1
2</pre>
</div>
   </div>
  </div>
 </div>



 <div class="refsect1 seealso" id="refsect1-closure.bind-seealso">
  <h3 class="title">Vedere anche:</h3>
  <ul class="simplelist">
   <li><a href="functions.anonymous.php" class="link">Anonymous functions</a></li>
   <li><span class="methodname"><a href="closure.bindto.php" class="methodname" rel="rdfs-seeAlso">Closure::bindTo()</a> - Duplica la closure con una nuova associazione all'oggetto e alla visibilit&agrave; della classe</span></li>
  </ul>
 </div>


</div><?php manual_footer($setup); ?>