Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getclosurecalledclass.xml Provide more detailed info + CS #4074

Merged
merged 2 commits into from
Nov 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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