<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.reflectionfunctionabstract.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'de',
  ),
  'this' => 
  array (
    0 => 'reflectionfunctionabstract.getclosurethis.php',
    1 => 'ReflectionFunctionAbstract::getClosureThis',
    2 => 'Returns the object which corresponds to $this inside a closure',
  ),
  'up' => 
  array (
    0 => 'class.reflectionfunctionabstract.php',
    1 => 'ReflectionFunctionAbstract',
  ),
  'prev' => 
  array (
    0 => 'reflectionfunctionabstract.getclosurescopeclass.php',
    1 => 'ReflectionFunctionAbstract::getClosureScopeClass',
  ),
  'next' => 
  array (
    0 => 'reflectionfunctionabstract.getclosureusedvariables.php',
    1 => 'ReflectionFunctionAbstract::getClosureUsedVariables',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/reflection/reflectionfunctionabstract/getclosurethis.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="reflectionfunctionabstract.getclosurethis" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ReflectionFunctionAbstract::getClosureThis</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.4.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">ReflectionFunctionAbstract::getClosureThis</span> &mdash; <span class="dc-title">Returns the object which corresponds to $this inside a closure</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-reflectionfunctionabstract.getclosurethis-description">
  <h3 class="title">Beschreibung</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>ReflectionFunctionAbstract::getClosureThis</strong></span>(): <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></div>

  <p class="para rdfs-comment">
   If the function is a non-static closure, get the object bound to <var class="varname">$this</var> inside the closure.
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-reflectionfunctionabstract.getclosurethis-parameters">
  <h3 class="title">Parameter-Liste</h3>
  <p class="para">Diese Funktion besitzt keine Parameter.</p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-reflectionfunctionabstract.getclosurethis-returnvalues">
  <h3 class="title">Rückgabewerte</h3>
  <p class="simpara">
   Return the object instance represented by <var class="varname">$this</var> inside
   the <span class="classname"><a href="class.closure.php" class="classname">Closure</a></span>.
   If the function is not a closure or if it has no <var class="varname">$this</var> <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>
   is returned instead.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-reflectionfunctionabstract.getclosurethis-examples">
  <h3 class="title">Beispiele</h3>
  <div class="example" id="example-1">
   <p><strong>Beispiel #1 
    Example showcasing difference between
    <span class="methodname"><a href="reflectionfunctionabstract.getclosurecalledclass.php" class="methodname">ReflectionFunctionAbstract::getClosureCalledClass()</a></span>,
    <span class="methodname"><a href="reflectionfunctionabstract.getclosurescopeclass.php" class="methodname">ReflectionFunctionAbstract::getClosureScopeClass()</a></span>,
    and <span class="methodname"><strong>ReflectionFunctionAbstract::getClosureThis()</strong></span>
    with a closure in the object context
   </strong></p>
   <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">class </span><span style="color: #0000BB">A<br /></span><span style="color: #007700">{<br />    public function </span><span style="color: #0000BB">getClosure</span><span style="color: #007700">()<br />    {<br />        </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">self</span><span style="color: #007700">::class, static::class);<br /><br />        return function() {};<br />    }<br />}<br /><br />class </span><span style="color: #0000BB">B </span><span style="color: #007700">extends </span><span style="color: #0000BB">A </span><span style="color: #007700">{}<br /><br /></span><span style="color: #0000BB">$b </span><span style="color: #007700">= new </span><span style="color: #0000BB">B</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$c </span><span style="color: #007700">= </span><span style="color: #0000BB">$b</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getClosure</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$r </span><span style="color: #007700">= new </span><span style="color: #0000BB">ReflectionFunction</span><span style="color: #007700">(</span><span style="color: #0000BB">$c</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$r</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getClosureThis</span><span style="color: #007700">()); </span><span style="color: #FF8000">// $this === $b, since a non-static closure take the object context<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$r</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getClosureScopeClass</span><span style="color: #007700">()); </span><span style="color: #FF8000">// Corresponds to the self::class resolution inside a closure<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$r</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getClosureCalledClass</span><span style="color: #007700">()); </span><span style="color: #FF8000">// Corresponds to the static::class resolution inside a closure<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>Das oben gezeigte Beispiel erzeugt folgende Ausgabe:</p></div>
   <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">string(1) &quot;A&quot;
string(1) &quot;B&quot;
object(B)#1 (0) {
}
object(ReflectionClass)#4 (1) {
  [&quot;name&quot;]=&gt;
  string(1) &quot;A&quot;
}
object(ReflectionClass)#4 (1) {
  [&quot;name&quot;]=&gt;
  string(1) &quot;B&quot;
}</pre>
</div>
   </div>
  </div>
  <div class="example" id="example-2">
   <p><strong>Beispiel #2 
    Example showcasing difference between
    <span class="methodname"><a href="reflectionfunctionabstract.getclosurecalledclass.php" class="methodname">ReflectionFunctionAbstract::getClosureCalledClass()</a></span>,
    <span class="methodname"><a href="reflectionfunctionabstract.getclosurescopeclass.php" class="methodname">ReflectionFunctionAbstract::getClosureScopeClass()</a></span>,
    and <span class="methodname"><strong>ReflectionFunctionAbstract::getClosureThis()</strong></span>
    with a static closure without an object context
   </strong></p>
   <div class="example-contents">
    <div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">class </span><span style="color: #0000BB">A<br /></span><span style="color: #007700">{<br />    public function </span><span style="color: #0000BB">getClosure</span><span style="color: #007700">()<br />    {<br />        </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">self</span><span style="color: #007700">::class, static::class);<br /><br />        return static function() {};<br />    }<br />}<br /><br />class </span><span style="color: #0000BB">B </span><span style="color: #007700">extends </span><span style="color: #0000BB">A </span><span style="color: #007700">{}<br /><br /></span><span style="color: #0000BB">$b </span><span style="color: #007700">= new </span><span style="color: #0000BB">B</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$c </span><span style="color: #007700">= </span><span style="color: #0000BB">$b</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getClosure</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$r </span><span style="color: #007700">= new </span><span style="color: #0000BB">ReflectionFunction</span><span style="color: #007700">(</span><span style="color: #0000BB">$c</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$r</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getClosureThis</span><span style="color: #007700">()); </span><span style="color: #FF8000">// NULL, since the pseudo-variable $this is not available in a static context<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$r</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getClosureScopeClass</span><span style="color: #007700">()); </span><span style="color: #FF8000">// Corresponds to the self::class resolution inside a closure<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$r</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getClosureCalledClass</span><span style="color: #007700">()); </span><span style="color: #FF8000">// Corresponds to the static::class resolution inside a closure<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>Das oben gezeigte Beispiel erzeugt folgende Ausgabe:</p></div>
   <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">string(1) &quot;A&quot;
string(1) &quot;B&quot;
NULL
object(ReflectionClass)#4 (1) {
  [&quot;name&quot;]=&gt;
  string(1) &quot;A&quot;
}
object(ReflectionClass)#4 (1) {
  [&quot;name&quot;]=&gt;
  string(1) &quot;B&quot;
}</pre>
</div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-reflectionfunctionabstract.getclosurethis-seealso">
  <h3 class="title">Siehe auch</h3>
  <ul class="simplelist">
   <li><span class="methodname"><a href="reflectionfunctionabstract.getclosurecalledclass.php" class="methodname" rel="rdfs-seeAlso">ReflectionFunctionAbstract::getClosureCalledClass()</a> - Returns the class corresponding to static:: inside a closure</span></li>
   <li><span class="methodname"><a href="reflectionfunctionabstract.getclosurescopeclass.php" class="methodname" rel="rdfs-seeAlso">ReflectionFunctionAbstract::getClosureScopeClass()</a> - Returns the class corresponding to the scope inside a closure</span></li>
   <li><a href="language.oop5.late-static-bindings.php" class="xref">Sp&auml;te statische Bindung</a></li>
  </ul>
 </div>


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