<?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 => 'pt_BR',
  ),
  'this' => 
  array (
    0 => 'reflectionfunctionabstract.getclosurethis.php',
    1 => 'ReflectionFunctionAbstract::getClosureThis',
    2 => 'Retorna o objeto que corresponde a $this dentro de uma 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' => 'pt_BR',
    '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">Retorna o objeto que corresponde a $this dentro de uma closure</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-reflectionfunctionabstract.getclosurethis-description">
  <h3 class="title">Descrição</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">
   Se a função for um Closure não estático, pega o objeto <var class="varname">$this</var> dentro do Closure.
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-reflectionfunctionabstract.getclosurethis-parameters">
  <h3 class="title">Parâmetros</h3>
  <p class="para">Esta função não possui parâmetros.</p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-reflectionfunctionabstract.getclosurethis-returnvalues">
  <h3 class="title">Valor Retornado</h3>
  <p class="simpara">
   Retorna a instância do objeto representado por <var class="varname">$this</var> dentro
   da <span class="classname"><a href="class.closure.php" class="classname">Closure</a></span>.
   Se a função não for uma closure ou se não tiver <var class="varname">$this</var>,
   retorna <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-reflectionfunctionabstract.getclosurethis-examples">
  <h3 class="title">Exemplos</h3>
  <div class="example" id="example-1">
   <p><strong>Exemplo #1 
    Exemplo que mostra a diferença entre
    <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>,
    e <span class="methodname"><strong>ReflectionFunctionAbstract::getClosureThis()</strong></span>
    com uma closure no contexto de objeto
   </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, já que uma closure não estática toma o contexto de objeto<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">// Corresponde a resolver self::class dentro de uma 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">// Corresponde a resolver static::class dentro de uma closure<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>O exemplo acima produzirá:</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>Exemplo #2 
    Exemplo que mostra a diferença entre
    <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>,
    e <span class="methodname"><strong>ReflectionFunctionAbstract::getClosureThis()</strong></span>
    com uma closure estática sem um contexto de objeto
   </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, já que a pseudo-variável $this não está disponível no contexto estático<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">// Corresponde a resolver self::class dentro de uma 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">// Corresponde a resolver static::class dentro de uma closure<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>O exemplo acima produzirá:</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">Veja Também</h3>
  <ul class="simplelist">
   <li><span class="methodname"><a href="reflectionfunctionabstract.getclosurecalledclass.php" class="methodname" rel="rdfs-seeAlso">ReflectionFunctionAbstract::getClosureCalledClass()</a> - Retorna a classe correspondente a static:: dentro de uma closure</span></li>
   <li><span class="methodname"><a href="reflectionfunctionabstract.getclosurescopeclass.php" class="methodname" rel="rdfs-seeAlso">ReflectionFunctionAbstract::getClosureScopeClass()</a> - Retorna a classe correspondente ao escopo dentro de uma closure</span></li>
   <li><a href="language.oop5.late-static-bindings.php" class="xref">Vincula&ccedil;&otilde;es Est&aacute;ticas Tardias</a></li>
  </ul>
 </div>


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