Skip to content

Commit ca94d55

Browse files
committed
Mark DOM classes as not serializable
1 parent 1c675b9 commit ca94d55

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

ext/dom/php_dom.stub.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public function after(...$nodes): void;
5656
public function replaceWith(...$nodes): void;
5757
}
5858

59+
/** @not-serializable */
5960
class DOMNode
6061
{
6162
/** @readonly */
@@ -155,6 +156,7 @@ public function removeChild(DOMNode $child) {}
155156
public function replaceChild(DOMNode $node, DOMNode $child) {}
156157
}
157158

159+
/** @not-serializable */
158160
class DOMNameSpaceNode
159161
{
160162
/** @readonly */
@@ -654,6 +656,7 @@ public function __construct(string $name, string $value = "") {}
654656
}
655657

656658
#ifdef LIBXML_XPATH_ENABLED
659+
/** @not-serializable */
657660
class DOMXPath
658661
{
659662
/** @readonly */

ext/dom/php_dom_arginfo.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 3db2a5e01c88b189f2d58aa67b598653ebde6a76 */
2+
* Stub hash: cff5c4b824da940f151617d08bb6b2419a9d26e9 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_dom_import_simplexml, 0, 1, DOMElement, 0)
55
ZEND_ARG_TYPE_INFO(0, node, IS_OBJECT, 0)
@@ -989,6 +989,7 @@ static zend_class_entry *register_class_DOMNode(void)
989989

990990
INIT_CLASS_ENTRY(ce, "DOMNode", class_DOMNode_methods);
991991
class_entry = zend_register_internal_class_ex(&ce, NULL);
992+
class_entry->ce_flags |= ZEND_ACC_NOT_SERIALIZABLE;
992993

993994
zval property_nodeName_default_value;
994995
ZVAL_UNDEF(&property_nodeName_default_value);
@@ -1103,6 +1104,7 @@ static zend_class_entry *register_class_DOMNameSpaceNode(void)
11031104

11041105
INIT_CLASS_ENTRY(ce, "DOMNameSpaceNode", class_DOMNameSpaceNode_methods);
11051106
class_entry = zend_register_internal_class_ex(&ce, NULL);
1107+
class_entry->ce_flags |= ZEND_ACC_NOT_SERIALIZABLE;
11061108

11071109
zval property_nodeName_default_value;
11081110
ZVAL_UNDEF(&property_nodeName_default_value);
@@ -1654,6 +1656,7 @@ static zend_class_entry *register_class_DOMXPath(void)
16541656

16551657
INIT_CLASS_ENTRY(ce, "DOMXPath", class_DOMXPath_methods);
16561658
class_entry = zend_register_internal_class_ex(&ce, NULL);
1659+
class_entry->ce_flags |= ZEND_ACC_NOT_SERIALIZABLE;
16571660

16581661
zend_string *property_document_class_DOMDocument = zend_string_init("DOMDocument", sizeof("DOMDocument")-1, 1);
16591662
zval property_document_default_value;

ext/dom/tests/not_serializable.phpt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--TEST--
2+
DOM classes are not serializable
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
8+
$doc = new DOMDocument();
9+
$doc->loadXML('<root><node/></root>');
10+
try {
11+
serialize($doc);
12+
} catch (Exception $e) {
13+
echo $e->getMessage(), "\n";
14+
}
15+
16+
$node = $doc->documentElement;
17+
try {
18+
serialize($node);
19+
} catch (Exception $e) {
20+
echo $e->getMessage(), "\n";
21+
}
22+
23+
$xpath = new DOMXPath($doc);
24+
try {
25+
serialize($xpath);
26+
} catch (Exception $e) {
27+
echo $e->getMessage(), "\n";
28+
}
29+
30+
$ns = $xpath->query('//namespace::*')->item(0);
31+
try {
32+
serialize($ns);
33+
} catch (Exception $e) {
34+
echo $e->getMessage(), "\n";
35+
}
36+
37+
?>
38+
--EXPECT--
39+
Serialization of 'DOMDocument' is not allowed
40+
Serialization of 'DOMElement' is not allowed
41+
Serialization of 'DOMXPath' is not allowed
42+
Serialization of 'DOMNameSpaceNode' is not allowed

0 commit comments

Comments
 (0)