language/predefined/closure/bindto.xml
2a4874ed531bcc223ca4bc1b4f9a5292594abaea
...
...
@@ -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>
...
...
@@ -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