Skip to content

Commit

Permalink
ReflectionFunctionAbstract::getClosureCalledClass() Improve descripti…
Browse files Browse the repository at this point in the history
…on + CS (#4074)

Co-authored-by: Tim Düsterhus <[email protected]>
  • Loading branch information
mmalferov and TimWolla authored Nov 16, 2024
1 parent 68e52ef commit 1870b4c
Showing 1 changed file with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</methodsynopsis>
<simpara>
Returns the class as a <classname>ReflectionClass</classname> that
corresponds to <literal>static::</literal> inside the
corresponds to resolving the class name corresponding to <literal>static::</literal> inside the
<classname>Closure</classname>.
</simpara>
</refsect1>
Expand Down Expand Up @@ -41,31 +41,31 @@
<methodname>ReflectionFunctionAbstract::getClosureCalledClass</methodname>,
<methodname>ReflectionFunctionAbstract::getClosureScopeClass</methodname>,
and <methodname>ReflectionFunctionAbstract::getClosureThis</methodname>
with an instance method
with a closure in the object context
</title>
<programlisting role="php">
<![CDATA[
<?php
class A {
public function getClosure() {
class A
{
public function getClosure()
{
var_dump(self::class, static::class);
return function () {
};
return function() {};
}
}
class B extends A {
}
class B extends A {}
$b = new B();
$c = $b->getClosure();
$r = new ReflectionFunction($c);
var_dump($r->getClosureThis()); // $this === $b
var_dump($r->getClosureScopeClass()); // self::class
var_dump($r->getClosureCalledClass()); // static::class
var_dump($r->getClosureThis()); // $this === $b, since a non-static closure take the object context
var_dump($r->getClosureScopeClass()); // Corresponds to the self::class resolution inside a closure
var_dump($r->getClosureCalledClass()); // Corresponds to the static::class resolution inside a closure
?>
]]>
Expand Down Expand Up @@ -94,31 +94,31 @@ object(ReflectionClass)#4 (1) {
<methodname>ReflectionFunctionAbstract::getClosureCalledClass</methodname>,
<methodname>ReflectionFunctionAbstract::getClosureScopeClass</methodname>,
and <methodname>ReflectionFunctionAbstract::getClosureThis</methodname>
with a static method
with a static closure without an object context
</title>
<programlisting role="php">
<![CDATA[
<?php
class A {
public function getClosure() {
class A
{
public function getClosure()
{
var_dump(self::class, static::class);
return static function () {
};
return static function() {};
}
}
class B extends A {
}
class B extends A {}
$b = new B();
$c = $b->getClosure();
$r = new ReflectionFunction($c);
var_dump($r->getClosureThis()); // NULL
var_dump($r->getClosureScopeClass()); // self::class
var_dump($r->getClosureCalledClass()); // static::class
var_dump($r->getClosureThis()); // NULL, since the pseudo-variable $this is not available in a static context
var_dump($r->getClosureScopeClass()); // Corresponds to the self::class resolution inside a closure
var_dump($r->getClosureCalledClass()); // Corresponds to the static::class resolution inside a closure
?>
]]>
Expand Down

0 comments on commit 1870b4c

Please sign in to comment.