language/oop5/overloading.xml
2ab7e9d763666526942ed4477c4f876beb160892
...
...
@@ -35,53 +35,13 @@
35
35
<note>
36
36
<para>
37
37
PHP's interpretation of <quote>overloading</quote> is
38
-
different than most object oriented languages. Overloading
38
+
different than most object-oriented languages. Overloading
39
39
traditionally provides the ability to have multiple methods
40
40
with the same name but different quantities and types of
41
41
arguments.
42
42
</para>
43
43
</note>
44
44

45
-

46
-
<sect2 xml:id="language.oop5.overloading.changelog">
47
-
&reftitle.changelog;
48
-
<para>
49
-
<informaltable>
50
-
<tgroup cols="2">
51
-
<thead>
52
-
<row>
53
-
<entry>&Version;</entry>
54
-
<entry>&Description;</entry>
55
-
</row>
56
-
</thead>
57
-
<tbody>
58
-
<row>
59
-
<entry>5.3.0</entry>
60
-
<entry>
61
-
Added <link linkend="object.callstatic">__callStatic()</link>.
62
-
Added warning to enforce public visibility and non-static declaration.
63
-
</entry>
64
-
</row>
65
-
<row>
66
-
<entry>5.1.0</entry>
67
-
<entry>
68
-
Added <link linkend="object.isset">__isset()</link> and <link linkend="object.unset">__unset()</link>.
69
-
Added support for <link linkend="object.get">__get()</link> for overloading of private properties.
70
-
</entry>
71
-
</row>
72
-
<row>
73
-
<entry>5.0.0</entry>
74
-
<entry>
75
-
Added <link linkend="object.get">__get()</link>.
76
-
</entry>
77
-
</row>
78
-
</tbody>
79
-
</tgroup>
80
-
</informaltable>
81
-
</para>
82
-
</sect2>
83
-

84
-

85
45
<sect2 xml:id="language.oop5.overloading.members">
86
46
<title>Property overloading</title>
87
47

...
...
@@ -105,23 +65,24 @@
105
65

106
66
<para>
107
67
<link linkend="object.set">__set()</link> is run when writing data to
108
-
inaccessible properties.
68
+
inaccessible (protected or private) or non-existing properties.
109
69
</para>
110
70

111
71
<para>
112
72
<link linkend="object.get">__get()</link> is utilized for reading data from
113
-
inaccessible properties.
73
+
inaccessible (protected or private) or non-existing properties.
114
74
</para>
115
75

116
76
<para>
117
77
<link linkend="object.isset">__isset()</link> is triggered by calling
118
78
<function>isset</function> or <function>empty</function>
119
-
on inaccessible properties.
79
+
on inaccessible (protected or private) or non-existing properties.
120
80
</para>
121
81

122
82
<para>
123
83
<link linkend="object.unset">__unset()</link> is invoked when
124
-
<function>unset</function> is used on inaccessible properties.
84
+
<function>unset</function> is used on inaccessible (protected or private)
85
+
or non-existing properties.
125
86
</para>
126
87

127
88
<para>
...
...
@@ -136,8 +97,8 @@
136
97
Property overloading only works in object context. These magic
137
98
methods will not be triggered in static context. Therefore
138
99
these methods should not be declared
139
-
<link linkend="language.oop5.static">static</link>. As of PHP
140
-
5.3.0, a warning is issued if one of the magic overloading
100
+
<link linkend="language.oop5.static">static</link>.
101
+
A warning is issued if one of the magic overloading
141
102
methods is declared <literal>static</literal>.
142
103
</para>
143
104

...
...
@@ -151,6 +112,18 @@
151
112
</para>
152
113
</note>
153
114

115
+
<note>
116
+
<para>
117
+
PHP will not call an overloaded method from within the same overloaded method.
118
+
That means, for example, writing <code>return $this->foo</code> inside of
119
+
<link linkend="object.get">__get()</link> will return <literal>null</literal>
120
+
and raise an <constant>E_WARNING</constant> if there is no <literal>foo</literal> property defined,
121
+
rather than calling <link linkend="object.get">__get()</link> a second time.
122
+
However, overload methods may invoke other overload methods implicitly (such as
123
+
<link linkend="object.set">__set()</link> triggering <link linkend="object.get">__get()</link>).
124
+
</para>
125
+
</note>
126
+

154
127
<example>
155
128
<title>
156
129
Overloading properties via the <link linkend="object.get">__get()</link>,
...
...
@@ -193,14 +166,12 @@ class PropertyTest
193
166
return null;
194
167
}
195
168

196
-
/** As of PHP 5.1.0 */
197
169
public function __isset($name)
198
170
{
199
171
echo "Is '$name' set?\n";
200
172
return isset($this->data[$name]);
201
173
}
202
174

203
-
/** As of PHP 5.1.0 */
204
175
public function __unset($name)
205
176
{
206
177
echo "Unsetting '$name'\n";
...
...
@@ -314,7 +285,6 @@ class MethodTest
314
285
. implode(', ', $arguments). "\n";
315
286
}
316
287

317
-
/** As of PHP 5.3.0 */
318
288
public static function __callStatic($name, $arguments)
319
289
{
320
290
// Note: value of $name is case sensitive.
...
...
@@ -326,7 +296,7 @@ class MethodTest
326
296
$obj = new MethodTest;
327
297
$obj->runTest('in object context');
328
298

329
-
MethodTest::runTest('in static context'); // As of PHP 5.3.0
299
+
MethodTest::runTest('in static context');
330
300
?>
331
301
]]>
332
302
</programlisting>
...
...
@@ -342,7 +312,6 @@ Calling static method 'runTest' in static context
342
312
</sect2>
343
313

344
314
</sect1>
345
-

346
315
<!-- Keep this comment at the end of the file
347
316
Local variables:
348
317
mode: sgml
349
318