reference/dom/domdocument/registernodeclass.xml
0e2dfef689e3b40b8a826a0f64ba741863ee8c2a
0e2dfef689e3b40b8a826a0f64ba741863ee8c2a
...
...
@@ -7,8 +7,8 @@
7
7
</refnamediv>
8
8
<refsect1 role="description">
9
9
&reftitle.description;
10
-
<methodsynopsis>
11
-
<modifier>public</modifier> <type>bool</type><methodname>DOMDocument::registerNodeClass</methodname>
10
+
<methodsynopsis role="DOMDocument">
11
+
<modifier>public</modifier> <type>true</type><methodname>DOMDocument::registerNodeClass</methodname>
12
12
<methodparam><type>string</type><parameter>baseClass</parameter></methodparam>
13
13
<methodparam><type class="union"><type>string</type><type>null</type></type><parameter>extendedClass</parameter></methodparam>
14
14
</methodsynopsis>
...
...
@@ -20,6 +20,11 @@
20
20
<para>
21
21
This method is not part of the DOM standard.
22
22
</para>
23
+
<caution>
24
+
<simpara>
25
+
The constructor of the objects of the registered node classes is not called.
26
+
</simpara>
27
+
</caution>
23
28
</refsect1>
24
29
25
30
<refsect1 role="parameters">
...
...
@@ -52,10 +57,33 @@
52
57
<refsect1 role="returnvalues">
53
58
&reftitle.returnvalues;
54
59
<para>
55
-
&return.success;
60
+
&return.true.always;
56
61
</para>
57
62
</refsect1>
58
63
64
+
<refsect1 role="changelog">
65
+
&reftitle.changelog;
66
+
<informaltable>
67
+
<tgroup cols="2">
68
+
<thead>
69
+
<row>
70
+
<entry>&Version;</entry>
71
+
<entry>&Description;</entry>
72
+
</row>
73
+
</thead>
74
+
<tbody>
75
+
<row>
76
+
<entry>8.4.0</entry>
77
+
<entry>
78
+
<methodname>DOMDocument::registerNodeClass</methodname>
79
+
now has a tentative return of <type>true</type>.
80
+
</entry>
81
+
</row>
82
+
</tbody>
83
+
</tgroup>
84
+
</informaltable>
85
+
</refsect1>
86
+
59
87
<refsect1 role="examples">
60
88
&reftitle.examples;
61
89
<para>
...
...
@@ -138,33 +166,44 @@ text in child
138
166
<para>
139
167
When instantiating a custom <classname>DOMDocument</classname> the
140
168
<varname>ownerDocument</varname> property will refer to the instantiated
141
-
class, meaning there is no need (and in fact not possible) to use
169
+
class. However, if all references to that class are removed, it
170
+
will be destroyed and new <classname>DOMDocument</classname> will be
171
+
created instead. For that reason you might use
142
172
<function>DOMDocument::registerNodeClass</function> with
143
173
<classname>DOMDocument</classname>
144
174
</para>
145
175
<programlisting role="php">
146
176
<![CDATA[
147
177
<?php
148
-
class myDOMDocument extends DOMDocument {
178
+
class MyDOMDocument extends DOMDocument {
149
179
}
150
180
151
-
class myOtherDOMDocument extends DOMDocument {
181
+
class MyOtherDOMDocument extends DOMDocument {
152
182
}
153
183
154
-
// Create myDOMDocument with some XML
155
-
$doc = new myDOMDocument;
184
+
// Create MyDOMDocument with some XML
185
+
$doc = new MyDOMDocument;
156
186
$doc->loadXML("<root><element><child>text in child</child></element></root>");
157
187
158
188
$child = $doc->getElementsByTagName("child")->item(0);
159
189
160
-
// The current owner of the node is myDOMDocument
190
+
// The current owner of the node is MyDOMDocument
191
+
var_dump(get_class($child->ownerDocument));
192
+
// MyDOMDocument is destroyed
193
+
unset($doc);
194
+
// And new DOMDocument instance is created
161
195
var_dump(get_class($child->ownerDocument));
162
196
163
-
// Import a node from myDOMDocument
164
-
$newdoc = new myOtherDOMDocument;
197
+
// Import a node from MyDOMDocument
198
+
$newdoc = new MyOtherDOMDocument;
165
199
$child = $newdoc->importNode($child);
166
200
167
-
// The new owner of the node has changed to myOtherDOMDocument
201
+
// Register custom DOMDocument
202
+
$newdoc->registerNodeClass("DOMDocument", "MyOtherDOMDocument");
203
+
204
+
var_dump(get_class($child->ownerDocument));
205
+
unset($doc);
206
+
// New MyOtherDOMDocument is created
168
207
var_dump(get_class($child->ownerDocument));
169
208
?>
170
209
]]>
...
...
@@ -172,8 +211,10 @@ var_dump(get_class($child->ownerDocument));
172
211
&example.outputs;
173
212
<screen role="xml">
174
213
<![CDATA[
175
-
string(13) "myDOMDocument"
176
-
string(18) "myOtherDOMDocument"
214
+
string(13) "MyDOMDocument"
215
+
string(11) "DOMDocument"
216
+
string(18) "MyOtherDOMDocument"
217
+
string(18) "MyOtherDOMDocument"
177
218
]]>
178
219
</screen>
179
220
</example>
180
221