Skip to content

Commit 1870b4c

Browse files
mmalferovTimWolla
andauthored
ReflectionFunctionAbstract::getClosureCalledClass() Improve description + CS (#4074)
Co-authored-by: Tim Düsterhus <[email protected]>
1 parent 68e52ef commit 1870b4c

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

reference/reflection/reflectionfunctionabstract/getclosurecalledclass.xml

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</methodsynopsis>
1414
<simpara>
1515
Returns the class as a <classname>ReflectionClass</classname> that
16-
corresponds to <literal>static::</literal> inside the
16+
corresponds to resolving the class name corresponding to <literal>static::</literal> inside the
1717
<classname>Closure</classname>.
1818
</simpara>
1919
</refsect1>
@@ -41,31 +41,31 @@
4141
<methodname>ReflectionFunctionAbstract::getClosureCalledClass</methodname>,
4242
<methodname>ReflectionFunctionAbstract::getClosureScopeClass</methodname>,
4343
and <methodname>ReflectionFunctionAbstract::getClosureThis</methodname>
44-
with an instance method
44+
with a closure in the object context
4545
</title>
4646
<programlisting role="php">
4747
<![CDATA[
4848
<?php
4949
50-
class A {
51-
public function getClosure() {
50+
class A
51+
{
52+
public function getClosure()
53+
{
5254
var_dump(self::class, static::class);
53-
return function () {
5455
55-
};
56+
return function() {};
5657
}
5758
}
5859
59-
class B extends A {
60-
61-
}
60+
class B extends A {}
6261
6362
$b = new B();
6463
$c = $b->getClosure();
6564
$r = new ReflectionFunction($c);
66-
var_dump($r->getClosureThis()); // $this === $b
67-
var_dump($r->getClosureScopeClass()); // self::class
68-
var_dump($r->getClosureCalledClass()); // static::class
65+
66+
var_dump($r->getClosureThis()); // $this === $b, since a non-static closure take the object context
67+
var_dump($r->getClosureScopeClass()); // Corresponds to the self::class resolution inside a closure
68+
var_dump($r->getClosureCalledClass()); // Corresponds to the static::class resolution inside a closure
6969
7070
?>
7171
]]>
@@ -94,31 +94,31 @@ object(ReflectionClass)#4 (1) {
9494
<methodname>ReflectionFunctionAbstract::getClosureCalledClass</methodname>,
9595
<methodname>ReflectionFunctionAbstract::getClosureScopeClass</methodname>,
9696
and <methodname>ReflectionFunctionAbstract::getClosureThis</methodname>
97-
with a static method
97+
with a static closure without an object context
9898
</title>
9999
<programlisting role="php">
100100
<![CDATA[
101101
<?php
102102
103-
class A {
104-
public function getClosure() {
103+
class A
104+
{
105+
public function getClosure()
106+
{
105107
var_dump(self::class, static::class);
106-
return static function () {
107108
108-
};
109+
return static function() {};
109110
}
110111
}
111112
112-
class B extends A {
113-
114-
}
113+
class B extends A {}
115114
116115
$b = new B();
117116
$c = $b->getClosure();
118117
$r = new ReflectionFunction($c);
119-
var_dump($r->getClosureThis()); // NULL
120-
var_dump($r->getClosureScopeClass()); // self::class
121-
var_dump($r->getClosureCalledClass()); // static::class
118+
119+
var_dump($r->getClosureThis()); // NULL, since the pseudo-variable $this is not available in a static context
120+
var_dump($r->getClosureScopeClass()); // Corresponds to the self::class resolution inside a closure
121+
var_dump($r->getClosureCalledClass()); // Corresponds to the static::class resolution inside a closure
122122
123123
?>
124124
]]>

0 commit comments

Comments
 (0)