language/predefined/closure/bindto.xml
80720e59fc88b2522fe2e119b0148caaaa214b0b
...
...
@@ -1,6 +1,5 @@
1
1
<?xml version="1.0" encoding="utf-8"?>
2
2
<!-- $Revision$ -->
3
-

4
3
<refentry xml:id="closure.bindto" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
5
4
<refnamediv>
6
5
<refname>Closure::bindTo</refname>
...
...
@@ -11,11 +10,10 @@
11
10

12
11
<refsect1 role="description">
13
12
&reftitle.description;
14
-
<methodsynopsis>
15
-
<modifier>public</modifier> <type>Closure</type><methodname>Closure::bindTo</methodname>
16
-
<methodparam><type>object</type><parameter>newthis</parameter></methodparam>
17
-
<methodparam choice="opt"><type>mixed</type><parameter>newscope</parameter>
18
-
<initializer>'static'</initializer></methodparam>
13
+
<methodsynopsis role="Closure">
14
+
<modifier>public</modifier> <type class="union"><type>Closure</type><type>null</type></type><methodname>Closure::bindTo</methodname>
15
+
<methodparam><type class="union"><type>object</type><type>null</type></type><parameter>newThis</parameter></methodparam>
16
+
<methodparam choice="opt"><type class="union"><type>object</type><type>string</type><type>null</type></type><parameter>newScope</parameter><initializer>"static"</initializer></methodparam>
19
17
</methodsynopsis>
20
18
<para>
21
19
Create and return a new <link linkend="functions.anonymous">anonymous
...
...
@@ -29,18 +27,18 @@
29
27
which determines which private and protected members the anonymous
30
28
function will be able to access. Namely, the members that will be
31
29
visible are the same as if the anonymous function were a method of
32
-
the class given as value of the <parameter>newscope</parameter>
30
+
the class given as value of the <parameter>newScope</parameter>
33
31
parameter.
34
32
</para>
35
33

36
34
<para>
37
35
Static closures cannot have any bound object (the value of the parameter
38
-
<parameter>newthis</parameter> should be &null;), but this function can
36
+
<parameter>newThis</parameter> should be &null;), but this method can
39
37
nevertheless be used to change their class scope.
40
38
</para>
41
39

42
40
<para>
43
-
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
44
42
instance will imply being scoped and vice-versa. To this end,
45
43
non-static closures that are given a scope but a &null; instance are made
46
44
static and non-static non-scoped closures that are given a non-null
...
...
@@ -60,7 +58,7 @@
60
58
&reftitle.parameters;
61
59
<variablelist>
62
60
<varlistentry>
63
-
<term><parameter>newthis</parameter></term>
61
+
<term><parameter>newThis</parameter></term>
64
62
<listitem>
65
63
<para>
66
64
The object to which the given anonymous function should be bound, or
...
...
@@ -69,13 +67,14 @@
69
67
</listitem>
70
68
</varlistentry>
71
69
<varlistentry>
72
-
<term><parameter>newscope</parameter></term>
70
+
<term><parameter>newScope</parameter></term>
73
71
<listitem>
74
72
<para>
75
-
The class scope to which associate the closure is to be associated, or
73
+
The class scope to which the closure is to be associated, or
76
74
'static' to keep the current one. If an object is given, the type of the
77
75
object will be used instead. This determines the visibility of protected
78
76
and private methods of the bound object.
77
+
It is not allowed to pass (an object of) an internal class as this parameter.
79
78
</para>
80
79
</listitem>
81
80
</varlistentry>
...
...
@@ -86,7 +85,7 @@
86
85
&reftitle.returnvalues;
87
86
<para>
88
87
Returns the newly created <classname>Closure</classname> object
89
-
&return.falseforfailure;
88
+
or &null; on failure.
90
89
</para>
91
90
</refsect1>
92
91

...
...
@@ -98,13 +97,21 @@
98
97
<![CDATA[
99
98
<?php
100
99

101
-
class A {
102
-
function __construct($val) {
100
+
class A
101
+
{
102
+
private $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>
...
...
@@ -138,7 +147,6 @@ echo $cl(), "\n";
138
147
</refsect1>
139
148

140
149
</refentry>
141
-

142
150
<!-- Keep this comment at the end of the file
143
151
Local variables:
144
152
mode: sgml
145
153