xref: /PHP-8.3/ext/dom/tests/not_serializable.phpt (revision 24e5e4ec)
1--TEST--
2DOM classes are not serializable
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7
8$doc = new DOMDocument();
9$doc->loadXML('<root><node/></root>');
10try {
11    serialize($doc);
12} catch (Exception $e) {
13    echo $e->getMessage(), "\n";
14}
15
16$node = $doc->documentElement;
17try {
18    serialize($node);
19} catch (Exception $e) {
20    echo $e->getMessage(), "\n";
21}
22
23$xpath = new DOMXPath($doc);
24try {
25    serialize($xpath);
26} catch (Exception $e) {
27    echo $e->getMessage(), "\n";
28}
29
30$ns = $xpath->query('//namespace::*')->item(0);
31try {
32    serialize($ns);
33} catch (Exception $e) {
34    echo $e->getMessage(), "\n";
35}
36
37?>
38--EXPECT--
39Serialization of 'DOMDocument' is not allowed, unless serialization methods are implemented in a subclass
40Serialization of 'DOMElement' is not allowed, unless serialization methods are implemented in a subclass
41Serialization of 'DOMXPath' is not allowed
42Serialization of 'DOMNameSpaceNode' is not allowed, unless serialization methods are implemented in a subclass
43