|
13 | 13 | </methodsynopsis>
|
14 | 14 | <simpara>
|
15 | 15 | 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 |
17 | 17 | <classname>Closure</classname>.
|
18 | 18 | </simpara>
|
19 | 19 | </refsect1>
|
|
41 | 41 | <methodname>ReflectionFunctionAbstract::getClosureCalledClass</methodname>,
|
42 | 42 | <methodname>ReflectionFunctionAbstract::getClosureScopeClass</methodname>,
|
43 | 43 | and <methodname>ReflectionFunctionAbstract::getClosureThis</methodname>
|
44 |
| - with an instance method |
| 44 | + with a closure in the object context |
45 | 45 | </title>
|
46 | 46 | <programlisting role="php">
|
47 | 47 | <![CDATA[
|
48 | 48 | <?php
|
49 | 49 |
|
50 |
| -class A { |
51 |
| - public function getClosure() { |
| 50 | +class A |
| 51 | +{ |
| 52 | + public function getClosure() |
| 53 | + { |
52 | 54 | var_dump(self::class, static::class);
|
53 |
| - return function () { |
54 | 55 |
|
55 |
| - }; |
| 56 | + return function() {}; |
56 | 57 | }
|
57 | 58 | }
|
58 | 59 |
|
59 |
| -class B extends A { |
60 |
| -
|
61 |
| -} |
| 60 | +class B extends A {} |
62 | 61 |
|
63 | 62 | $b = new B();
|
64 | 63 | $c = $b->getClosure();
|
65 | 64 | $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 |
69 | 69 |
|
70 | 70 | ?>
|
71 | 71 | ]]>
|
@@ -94,31 +94,31 @@ object(ReflectionClass)#4 (1) {
|
94 | 94 | <methodname>ReflectionFunctionAbstract::getClosureCalledClass</methodname>,
|
95 | 95 | <methodname>ReflectionFunctionAbstract::getClosureScopeClass</methodname>,
|
96 | 96 | and <methodname>ReflectionFunctionAbstract::getClosureThis</methodname>
|
97 |
| - with a static method |
| 97 | + with a static closure without an object context |
98 | 98 | </title>
|
99 | 99 | <programlisting role="php">
|
100 | 100 | <![CDATA[
|
101 | 101 | <?php
|
102 | 102 |
|
103 |
| -class A { |
104 |
| - public function getClosure() { |
| 103 | +class A |
| 104 | +{ |
| 105 | + public function getClosure() |
| 106 | + { |
105 | 107 | var_dump(self::class, static::class);
|
106 |
| - return static function () { |
107 | 108 |
|
108 |
| - }; |
| 109 | + return static function() {}; |
109 | 110 | }
|
110 | 111 | }
|
111 | 112 |
|
112 |
| -class B extends A { |
113 |
| -
|
114 |
| -} |
| 113 | +class B extends A {} |
115 | 114 |
|
116 | 115 | $b = new B();
|
117 | 116 | $c = $b->getClosure();
|
118 | 117 | $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 |
122 | 122 |
|
123 | 123 | ?>
|
124 | 124 | ]]>
|
|
0 commit comments