language/predefined/closure/bindto.xml
80720e59fc88b2522fe2e119b0148caaaa214b0b
80720e59fc88b2522fe2e119b0148caaaa214b0b
...
...
@@ -10,7 +10,7 @@
10
10
11
11
<refsect1 role="description">
12
12
&reftitle.description;
13
-
<methodsynopsis>
13
+
<methodsynopsis role="Closure">
14
14
<modifier>public</modifier> <type class="union"><type>Closure</type><type>null</type></type><methodname>Closure::bindTo</methodname>
15
15
<methodparam><type class="union"><type>object</type><type>null</type></type><parameter>newThis</parameter></methodparam>
16
16
<methodparam choice="opt"><type class="union"><type>object</type><type>string</type><type>null</type></type><parameter>newScope</parameter><initializer>"static"</initializer></methodparam>
...
...
@@ -33,12 +33,12 @@
33
33
34
34
<para>
35
35
Static closures cannot have any bound object (the value of the parameter
36
-
<parameter>newThis</parameter> should be &null;), but this function can
36
+
<parameter>newThis</parameter> should be &null;), but this method can
37
37
nevertheless be used to change their class scope.
38
38
</para>
39
39
40
40
<para>
41
-
This function will ensure that for a non-static closure, having a bound
41
+
This method will ensure that for a non-static closure, having a bound
42
42
instance will imply being scoped and vice-versa. To this end,
43
43
non-static closures that are given a scope but a &null; instance are made
44
44
static and non-static non-scoped closures that are given a non-null
...
...
@@ -97,14 +97,21 @@
97
97
<![CDATA[
98
98
<?php
99
99
100
-
class A {
100
+
class A
101
+
{
101
102
private $val;
102
-
function __construct($val) {
103
+
104
+
public function __construct($val)
105
+
{
103
106
$this->val = $val;
104
107
}
105
-
function getClosure() {
106
-
//returns closure bound to this object and scope
107
-
return function() { return $this->val; };
108
+
109
+
public function getClosure()
110
+
{
111
+
// Returns closure bound to this object and scope
112
+
return function() {
113
+
return $this->val;
114
+
};
108
115
}
109
116
}
110
117
...
...
@@ -113,8 +120,10 @@ $ob2 = new A(2);
113
120
114
121
$cl = $ob1->getClosure();
115
122
echo $cl(), "\n";
123
+
116
124
$cl = $cl->bindTo($ob2);
117
125
echo $cl(), "\n";
126
+
118
127
?>
119
128
]]>
120
129
</programlisting>
121
130