reference/dom/domdocument/registernodeclass.xml
bb47f4433ac38d890373169666e82609d2ab0848
...
...
@@ -7,7 +7,7 @@
7
7
</refnamediv>
8
8
<refsect1 role="description">
9
9
&reftitle.description;
10
-
<methodsynopsis>
10
+
<methodsynopsis role="DOMDocument">
11
11
<modifier>public</modifier> <type>bool</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>
...
...
@@ -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">
...
...
@@ -138,33 +143,44 @@ text in child
138
143
<para>
139
144
When instantiating a custom <classname>DOMDocument</classname> the
140
145
<varname>ownerDocument</varname> property will refer to the instantiated
141
-
class, meaning there is no need (and in fact not possible) to use
146
+
class. However, if all references to that class are removed, it
147
+
will be destroyed and new <classname>DOMDocument</classname> will be
148
+
created instead. For that reason you might use
142
149
<function>DOMDocument::registerNodeClass</function> with
143
150
<classname>DOMDocument</classname>
144
151
</para>
145
152
<programlisting role="php">
146
153
<![CDATA[
147
154
<?php
148
-
class myDOMDocument extends DOMDocument {
155
+
class MyDOMDocument extends DOMDocument {
149
156
}
150
157

151
-
class myOtherDOMDocument extends DOMDocument {
158
+
class MyOtherDOMDocument extends DOMDocument {
152
159
}
153
160

154
-
// Create myDOMDocument with some XML
155
-
$doc = new myDOMDocument;
161
+
// Create MyDOMDocument with some XML
162
+
$doc = new MyDOMDocument;
156
163
$doc->loadXML("<root><element><child>text in child</child></element></root>");
157
164

158
165
$child = $doc->getElementsByTagName("child")->item(0);
159
166

160
-
// The current owner of the node is myDOMDocument
167
+
// The current owner of the node is MyDOMDocument
168
+
var_dump(get_class($child->ownerDocument));
169
+
// MyDOMDocument is destroyed
170
+
unset($doc);
171
+
// And new DOMDocument instance is created
161
172
var_dump(get_class($child->ownerDocument));
162
173

163
-
// Import a node from myDOMDocument
164
-
$newdoc = new myOtherDOMDocument;
174
+
// Import a node from MyDOMDocument
175
+
$newdoc = new MyOtherDOMDocument;
165
176
$child = $newdoc->importNode($child);
166
177

167
-
// The new owner of the node has changed to myOtherDOMDocument
178
+
// Register custom DOMDocument
179
+
$newdoc->registerNodeClass("DOMDocument", "MyOtherDOMDocument");
180
+

181
+
var_dump(get_class($child->ownerDocument));
182
+
unset($doc);
183
+
// New MyOtherDOMDocument is created
168
184
var_dump(get_class($child->ownerDocument));
169
185
?>
170
186
]]>
...
...
@@ -172,8 +188,10 @@ var_dump(get_class($child->ownerDocument));
172
188
&example.outputs;
173
189
<screen role="xml">
174
190
<![CDATA[
175
-
string(13) "myDOMDocument"
176
-
string(18) "myOtherDOMDocument"
191
+
string(13) "MyDOMDocument"
192
+
string(11) "DOMDocument"
193
+
string(18) "MyOtherDOMDocument"
194
+
string(18) "MyOtherDOMDocument"
177
195
]]>
178
196
</screen>
179
197
</example>
180
198