<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/reserved.interfaces.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'class.closure.php',
    1 => 'Closure',
    2 => 'The Closure class',
  ),
  'up' => 
  array (
    0 => 'reserved.interfaces.php',
    1 => 'Predefined Interfaces and Classes',
  ),
  'prev' => 
  array (
    0 => 'serializable.unserialize.php',
    1 => 'Serializable::unserialize',
  ),
  'next' => 
  array (
    0 => 'closure.construct.php',
    1 => 'Closure::__construct',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'language/predefined/closure.xml',
  ),
  'history' => 
  array (
  ),
  'extra_header_links' => 
  array (
    'rel' => 'alternate',
    'href' => '/manual/en/feeds/class.closure.atom',
    'type' => 'application/atom+xml',
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="class.closure" class="reference">

 <h1 class="title">The Closure class</h1>
 

 <div class="partintro"><p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8)</p>


  <div class="section" id="closure.intro">
   <h2 class="title">Introduction</h2>
   <p class="para">
    Class used to represent <a href="functions.anonymous.php" class="link">anonymous
    functions</a>.
   </p>

   <p class="para">
    Anonymous functions yield objects of this type.
    This class has methods that allow
    further control of the anonymous function after it has been created.
   </p>

   <p class="para">
    Besides the methods listed here, this class also has an
    <code class="literal">__invoke</code> method. This is for consistency with other
    classes that implement <a href="language.oop5.magic.php#language.oop5.magic.invoke" class="link">calling
    magic</a>, as this method is not used for calling the function.
   </p>

  </div>


  <div class="section" id="closure.synopsis">
   <h2 class="title">Class synopsis</h2>


   <div class="classsynopsis"><div class="classsynopsisinfo">
    
     <span class="modifier">final</span>
     <span class="modifier">class</span> <strong class="classname"><strong class="classname">Closure</strong></strong>
     {</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* Methods */</div>
    <div class="constructorsynopsis dc-description">
   <span class="modifier">private</span> <span class="methodname"><a href="closure.construct.php" class="methodname">__construct</a></span>()</div>

    <div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><a href="closure.bind.php" class="methodname">bind</a></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>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="closure.bindto.php" class="methodname">bindTo</a></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>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="closure.call.php" class="methodname">call</a></span>(<span class="methodparam"><span class="type"><a href="language.types.object.php" class="type object">object</a></span> <code class="parameter">$newThis</code></span>, <span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">...$args</code></span>): <span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><a href="closure.fromcallable.php" class="methodname">fromCallable</a></span>(<span class="methodparam"><span class="type"><a href="language.types.callable.php" class="type callable">callable</a></span> <code class="parameter">$callback</code></span>): <span class="type"><a href="class.closure.php" class="type Closure">Closure</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><a href="closure.getcurrent.php" class="methodname">getCurrent</a></span>(): <span class="type"><a href="class.closure.php" class="type Closure">Closure</a></span></div>

   }</div>


  </div>

  <div class="section">
   <h2 class="title">Changelog</h2>
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.4.0</td>
       <td>
        The output of <span class="methodname"><strong>Closure::__debugInfo()</strong></span> now includes the
        name, line, and file of the closure.
       </td>
      </tr>

     </tbody>
    
   </table>

  </div>

 </div>

 




 




 




 




 




 





<h2>Table of Contents</h2><ul class="chunklist chunklist_reference"><li><a href="closure.construct.php">Closure::__construct</a> — Constructor that disallows instantiation</li><li><a href="closure.bind.php">Closure::bind</a> — Duplicates a closure with a specific bound object and class scope</li><li><a href="closure.bindto.php">Closure::bindTo</a> — Duplicates the closure with a new bound object and class scope</li><li><a href="closure.call.php">Closure::call</a> — Binds and calls the closure</li><li><a href="closure.fromcallable.php">Closure::fromCallable</a> — Converts a callable into a closure</li><li><a href="closure.getcurrent.php">Closure::getCurrent</a> — Returns the currently executing closure</li></ul>
</div>
<?php manual_footer($setup); ?>