|
| 1 | +<?xml version="1.0" encoding="utf-8"?> |
| 2 | +<!-- $Revision$ --> |
| 3 | +<!-- EN-Revision: 1870b4c6aa53e14eec6201eb63f28ed6be6349f7 Maintainer: mumumu Status: ready --> |
| 4 | +<refentry xml:id="reflectionfunctionabstract.getclosurecalledclass" xmlns="http://docbook.org/ns/docbook"> |
| 5 | + <refnamediv> |
| 6 | + <refname>ReflectionFunctionAbstract::getClosureCalledClass</refname> |
| 7 | + <refpurpose>クロージャ内部で static:: に対応するクラスを返す</refpurpose> |
| 8 | + </refnamediv> |
| 9 | + |
| 10 | + <refsect1 role="description"> |
| 11 | + &reftitle.description; |
| 12 | + <methodsynopsis role="ReflectionFunctionAbstract"> |
| 13 | + <modifier>public</modifier> <type class="union"><type>ReflectionClass</type><type>null</type></type><methodname>ReflectionFunctionAbstract::getClosureCalledClass</methodname> |
| 14 | + <void/> |
| 15 | + </methodsynopsis> |
| 16 | + <simpara> |
| 17 | + <classname>Closure</classname> 内部で <literal>static::</literal> |
| 18 | + に対応するクラス名に解決されるクラスを、<classname>ReflectionClass</classname> |
| 19 | + として返します。 |
| 20 | + </simpara> |
| 21 | + </refsect1> |
| 22 | + |
| 23 | + <refsect1 role="parameters"> |
| 24 | + &reftitle.parameters; |
| 25 | + &no.function.parameters; |
| 26 | + </refsect1> |
| 27 | + |
| 28 | + <refsect1 role="returnvalues"> |
| 29 | + &reftitle.returnvalues; |
| 30 | + <simpara> |
| 31 | + <classname>Closure</classname> 内部で <literal>static::</literal> |
| 32 | + で表現されるクラスに対応する <classname>ReflectionClass</classname> を返します。 |
| 33 | + 関数がクロージャでないか、グローバルスコープの場合は &null; を返します。 |
| 34 | + </simpara> |
| 35 | + </refsect1> |
| 36 | + |
| 37 | + <refsect1 role="examples"> |
| 38 | + &reftitle.examples; |
| 39 | + <example> |
| 40 | + <title> |
| 41 | + この例は、オブジェクトコンテキスト内部のクロージャについて、 |
| 42 | + <methodname>ReflectionFunctionAbstract::getClosureCalledClass</methodname>, |
| 43 | + <methodname>ReflectionFunctionAbstract::getClosureScopeClass</methodname>, |
| 44 | + <methodname>ReflectionFunctionAbstract::getClosureThis</methodname> |
| 45 | + の違いを示しています。 |
| 46 | + </title> |
| 47 | + <programlisting role="php"> |
| 48 | +<![CDATA[ |
| 49 | +<?php |
| 50 | +
|
| 51 | +class A |
| 52 | +{ |
| 53 | + public function getClosure() |
| 54 | + { |
| 55 | + var_dump(self::class, static::class); |
| 56 | +
|
| 57 | + return function() {}; |
| 58 | + } |
| 59 | +} |
| 60 | +
|
| 61 | +class B extends A {} |
| 62 | +
|
| 63 | +$b = new B(); |
| 64 | +$c = $b->getClosure(); |
| 65 | +$r = new ReflectionFunction($c); |
| 66 | +
|
| 67 | +var_dump($r->getClosureThis()); // $this === $b, since a non-static closure take the object context |
| 68 | +var_dump($r->getClosureScopeClass()); // Corresponds to the self::class resolution inside a closure |
| 69 | +var_dump($r->getClosureCalledClass()); // Corresponds to the static::class resolution inside a closure |
| 70 | +
|
| 71 | +?> |
| 72 | +]]> |
| 73 | + </programlisting> |
| 74 | + &example.outputs; |
| 75 | + <screen> |
| 76 | +<![CDATA[ |
| 77 | +string(1) "A" |
| 78 | +string(1) "B" |
| 79 | +object(B)#1 (0) { |
| 80 | +} |
| 81 | +object(ReflectionClass)#4 (1) { |
| 82 | + ["name"]=> |
| 83 | + string(1) "A" |
| 84 | +} |
| 85 | +object(ReflectionClass)#4 (1) { |
| 86 | + ["name"]=> |
| 87 | + string(1) "B" |
| 88 | +} |
| 89 | +]]> |
| 90 | + </screen> |
| 91 | + </example> |
| 92 | + <example> |
| 93 | + <title> |
| 94 | + この例は、オブジェクトコンテキストが存在しない static なクロージャについて、 |
| 95 | + <methodname>ReflectionFunctionAbstract::getClosureCalledClass</methodname>, |
| 96 | + <methodname>ReflectionFunctionAbstract::getClosureScopeClass</methodname>, |
| 97 | + <methodname>ReflectionFunctionAbstract::getClosureThis</methodname> |
| 98 | + の違いを示しています。 |
| 99 | + </title> |
| 100 | + <programlisting role="php"> |
| 101 | + <![CDATA[ |
| 102 | +<?php |
| 103 | +
|
| 104 | +class A |
| 105 | +{ |
| 106 | + public function getClosure() |
| 107 | + { |
| 108 | + var_dump(self::class, static::class); |
| 109 | +
|
| 110 | + return static function() {}; |
| 111 | + } |
| 112 | +} |
| 113 | +
|
| 114 | +class B extends A {} |
| 115 | +
|
| 116 | +$b = new B(); |
| 117 | +$c = $b->getClosure(); |
| 118 | +$r = new ReflectionFunction($c); |
| 119 | +
|
| 120 | +var_dump($r->getClosureThis()); // NULL, since the pseudo-variable $this is not available in a static context |
| 121 | +var_dump($r->getClosureScopeClass()); // Corresponds to the self::class resolution inside a closure |
| 122 | +var_dump($r->getClosureCalledClass()); // Corresponds to the static::class resolution inside a closure |
| 123 | +
|
| 124 | +?> |
| 125 | +]]> |
| 126 | + </programlisting> |
| 127 | + &example.outputs; |
| 128 | + <screen> |
| 129 | +<![CDATA[ |
| 130 | +string(1) "A" |
| 131 | +string(1) "B" |
| 132 | +NULL |
| 133 | +object(ReflectionClass)#4 (1) { |
| 134 | + ["name"]=> |
| 135 | + string(1) "A" |
| 136 | +} |
| 137 | +object(ReflectionClass)#4 (1) { |
| 138 | + ["name"]=> |
| 139 | + string(1) "B" |
| 140 | +} |
| 141 | +
|
| 142 | +]]> |
| 143 | + </screen> |
| 144 | + </example> |
| 145 | + </refsect1> |
| 146 | + |
| 147 | + <refsect1 role="seealso"> |
| 148 | + &reftitle.seealso; |
| 149 | + <simplelist> |
| 150 | + <member><methodname>ReflectionFunctionAbstract::getClosureScopeClass</methodname></member> |
| 151 | + <member><methodname>ReflectionFunctionAbstract::getClosureThis</methodname></member> |
| 152 | + <member><xref linkend="language.oop5.late-static-bindings" /></member> |
| 153 | + </simplelist> |
| 154 | + </refsect1> |
| 155 | + |
| 156 | +</refentry> |
| 157 | +<!-- Keep this comment at the end of the file |
| 158 | +Local variables: |
| 159 | +mode: sgml |
| 160 | +sgml-omittag:t |
| 161 | +sgml-shorttag:t |
| 162 | +sgml-minimize-attributes:nil |
| 163 | +sgml-always-quote-attributes:t |
| 164 | +sgml-indent-step:1 |
| 165 | +sgml-indent-data:t |
| 166 | +indent-tabs-mode:nil |
| 167 | +sgml-parent-document:nil |
| 168 | +sgml-default-dtd-file:"~/.phpdoc/manual.ced" |
| 169 | +sgml-exposed-tags:nil |
| 170 | +sgml-local-catalogs:nil |
| 171 | +sgml-local-ecat-files:nil |
| 172 | +End: |
| 173 | +vim600: syn=xml fen fdm=syntax fdl=2 si |
| 174 | +vim: et tw=78 syn=sgml |
| 175 | +vi: ts=1 sw=1 |
| 176 | +--> |
0 commit comments