Skip to content
Merged
Show file tree
Hide file tree
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
@@ -0,0 +1,175 @@
<?xml version="1.0" encoding="utf-8"?>
<refentry xml:id="reflectionfunctionabstract.getclosurecalledclass" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>ReflectionFunctionAbstract::getClosureCalledClass</refname>
<refpurpose>Returns the class corresponding to static:: inside a closure</refpurpose>
</refnamediv>

<refsect1 role="description">
&reftitle.description;
<methodsynopsis role="ReflectionFunctionAbstract">
<modifier>public</modifier> <type class="union"><type>ReflectionClass</type><type>null</type></type><methodname>ReflectionFunctionAbstract::getClosureCalledClass</methodname>
<void/>
</methodsynopsis>
<simpara>
Returns the class as a <classname>ReflectionClass</classname> that
corresponds to <literal>static::</literal> inside the
<classname>Closure</classname>.
</simpara>
</refsect1>

<refsect1 role="parameters">
&reftitle.parameters;
&no.function.parameters;
</refsect1>

<refsect1 role="returnvalues">
&reftitle.returnvalues;
<simpara>
Returns a <classname>ReflectionClass</classname> corresponding to the class
represented by <literal>static::</literal> in the <classname>Closure</classname>.
If the function is not a closure or if it has global scope &null;
is returned instead.
</simpara>
</refsect1>

<refsect1 role="examples">
&reftitle.examples;
<example>
<title>
Example showcasing difference between
<methodname>ReflectionFunctionAbstract::getClosureCalledClass</methodname>,
<methodname>ReflectionFunctionAbstract::getClosureScopeClass</methodname>,
and <methodname>ReflectionFunctionAbstract::getClosureThis</methodname>
with an instance method
</title>
<programlisting role="php">
<![CDATA[
<?php

class A {
public function getClosure() {
var_dump(self::class, static::class);
return function () {

};
}
}

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

?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
string(1) "A"
string(1) "B"
object(B)#1 (0) {
}
object(ReflectionClass)#4 (1) {
["name"]=>
string(1) "A"
}
object(ReflectionClass)#4 (1) {
["name"]=>
string(1) "B"
}
]]>
</screen>
</example>
<example>
<title>
Example showcasing difference between
<methodname>ReflectionFunctionAbstract::getClosureCalledClass</methodname>,
<methodname>ReflectionFunctionAbstract::getClosureScopeClass</methodname>,
and <methodname>ReflectionFunctionAbstract::getClosureThis</methodname>
with a static method
</title>
<programlisting role="php">
<![CDATA[
<?php

class A {
public function getClosure() {
var_dump(self::class, static::class);
return static function () {

};
}
}

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

?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
string(1) "A"
string(1) "B"
NULL
object(ReflectionClass)#4 (1) {
["name"]=>
string(1) "A"
}
object(ReflectionClass)#4 (1) {
["name"]=>
string(1) "B"
}

]]>
</screen>
</example>
</refsect1>

<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member><methodname>ReflectionFunctionAbstract::getClosureScopeClass</methodname></member>
<member><methodname>ReflectionFunctionAbstract::getClosureThis</methodname></member>
<member><xref linkend="language.oop5.late-static-bindings" /></member>
</simplelist>
</refsect1>

</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="reflectionfunctionabstract.getclosurescopeclass" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refentry xml:id="reflectionfunctionabstract.getclosurescopeclass" xmlns="http://docbook.org/ns/docbook" xmlns:xi="http://www.w3.org/2001/XInclude">
<refnamediv>
<refname>ReflectionFunctionAbstract::getClosureScopeClass</refname>
<refpurpose>Returns the scope class associated with the closure</refpurpose>
<refpurpose>Returns the class corresponding to the scope inside a closure</refpurpose>
</refnamediv>

<refsect1 role="description">
Expand All @@ -12,10 +12,11 @@
<modifier>public</modifier> <type class="union"><type>ReflectionClass</type><type>null</type></type><methodname>ReflectionFunctionAbstract::getClosureScopeClass</methodname>
<void/>
</methodsynopsis>
<para>
Get the class enclosing the closure declaration.
</para>

<simpara>
Returns the class as a <classname>ReflectionClass</classname> that
corresponds to the scope inside the
<classname>Closure</classname>.
</simpara>
</refsect1>

<refsect1 role="parameters">
Expand All @@ -25,11 +26,26 @@

<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns the class, or &null; if the function is not a closure or if there was no enclosing class.
</para>
<simpara>
Returns a <classname>ReflectionClass</classname> corresponding to the class
whose scope is being used inside the <classname>Closure</classname>.
If the function is not a closure or if it has global scope &null;
is returned instead.
</simpara>
</refsect1>

<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('reflectionfunctionabstract.getclosurecalledclass')/db:refsect1[@role='examples']/.)">
<xi:fallback/>
</xi:include>

<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member><methodname>ReflectionFunctionAbstract::getClosureCalledClass</methodname></member>
<member><methodname>ReflectionFunctionAbstract::getClosureThis</methodname></member>
<member><xref linkend="language.oop5.late-static-bindings" /></member>
</simplelist>
</refsect1>

</refentry>
<!-- Keep this comment at the end of the file
Expand Down
26 changes: 20 additions & 6 deletions reference/reflection/reflectionfunctionabstract/getclosurethis.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="reflectionfunctionabstract.getclosurethis" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refentry xml:id="reflectionfunctionabstract.getclosurethis" xmlns="http://docbook.org/ns/docbook" xmlns:xi="http://www.w3.org/2001/XInclude">
<refnamediv>
<refname>ReflectionFunctionAbstract::getClosureThis</refname>
<refpurpose>Returns this pointer bound to closure</refpurpose>
<refpurpose>Returns the object which corresponds to $this inside a closure</refpurpose>
</refnamediv>

<refsect1 role="description">
Expand All @@ -25,12 +25,26 @@

<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns <varname>$this</varname> pointer.
Returns &null; in case of an error.
</para>
<simpara>
Return the object instance represented by <varname>$this</varname> inside
the <classname>Closure</classname>.
If the function is not a closure or if it has no <varname>$this</varname> &null;
is returned instead.
</simpara>
</refsect1>

<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('reflectionfunctionabstract.getclosurecalledclass')/db:refsect1[@role='examples']/.)">
<xi:fallback/>
</xi:include>
Comment on lines +36 to +38
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh this is funky. This would also have been an option for the curl multi docs.


<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member><methodname>ReflectionFunctionAbstract::getClosureCalledClass</methodname></member>
<member><methodname>ReflectionFunctionAbstract::getClosureScopeClass</methodname></member>
<member><xref linkend="language.oop5.late-static-bindings" /></member>
</simplelist>
</refsect1>

</refentry>
<!-- Keep this comment at the end of the file
Expand Down
1 change: 1 addition & 0 deletions reference/reflection/versions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<function name="reflectionfunctionabstract" from="PHP 5 &gt;= 5.2.0, PHP 7, PHP 8"/>
<function name="reflectionfunctionabstract::__clone" from="PHP 5 &gt;= 5.2.0, PHP 7, PHP 8"/>
<function name="reflectionfunctionabstract::__tostring" from="PHP 5 &gt;= 5.2.0, PHP 7, PHP 8"/>
<function name="reflectionfunctionabstract::getclosurecalledclass" from="PHP 8 &gt;= 8.0.23, PHP 8 &gt;= 8.1.11"/>
<function name="reflectionfunctionabstract::getclosurescopeclass" from="PHP 5 &gt;= 5.4.0, PHP 7, PHP 8"/>
<function name="reflectionfunctionabstract::getclosurethis" from="PHP 5 &gt;= 5.4.0, PHP 7, PHP 8"/>
<function name="reflectionfunctionabstract::innamespace" from="PHP 5 &gt;= 5.3.0, PHP 7, PHP 8"/>
Expand Down