Skip to content

Commit af9fddd

Browse files
nielsdosbon
authored andcommitted
Align DOMChildNode parent checks with spec
Closes phpGH-11905.
1 parent a412e56 commit af9fddd

File tree

5 files changed

+83
-6
lines changed

5 files changed

+83
-6
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ PHP NEWS
44

55
- DOM:
66
. adoptNode now respects the strict error checking property. (nielsdos)
7+
. Align DOMChildNode parent checks with spec. (nielsdos)
78

89
- Opcache:
910
. Avoid resetting JIT counter handlers from multiple processes/threads.

UPGRADING

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ PHP 8.3 UPGRADE NOTES
4646
iterating over the WeakMap (reachability via iteration is considered weak).
4747
Previously, such entries would never be automatically removed.
4848

49+
- DOM:
50+
. DOMChildNode::after(), DOMChildNode::before(), DOMChildNode::replaceWith()
51+
on a node that has no parent is now a no-op instead of a hierarchy exception,
52+
which is the behaviour spec demands.
53+
. Using the DOMParentNode and DOMChildNode methods without a document now works
54+
instead of throwing a HIERARCHY_REQUEST_ERR DOMException. This is in line with
55+
the behaviour spec demands.
56+
4957
- FFI:
5058
. C functions that have a return type of void now return null instead of
5159
returning the following object object(FFI\CData:void) { }
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
--TEST--
2+
DOMChildNode methods without a parent
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
$doc = new DOMDocument;
8+
$doc->loadXML(<<<XML
9+
<?xml version="1.0"?>
10+
<container>
11+
<child/>
12+
</container>
13+
XML);
14+
15+
$container = $doc->documentElement;
16+
$child = $container->firstElementChild;
17+
18+
$test = $doc->createElement('foo');
19+
foreach (['before', 'after', 'replaceWith'] as $method) {
20+
echo "--- $method ---\n";
21+
$test->$method($child);
22+
echo $doc->saveXML();
23+
echo $doc->saveXML($test), "\n";
24+
}
25+
?>
26+
--EXPECT--
27+
--- before ---
28+
<?xml version="1.0"?>
29+
<container>
30+
<child/>
31+
</container>
32+
<foo/>
33+
--- after ---
34+
<?xml version="1.0"?>
35+
<container>
36+
<child/>
37+
</container>
38+
<foo/>
39+
--- replaceWith ---
40+
<?xml version="1.0"?>
41+
<container>
42+
<child/>
43+
</container>
44+
<foo/>

ext/dom/tests/bug79968.phpt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ dom
77

88
$cdata = new DOMText;
99

10-
try {
11-
$cdata->before("string");
12-
} catch (DOMException $e) {
13-
echo $e->getMessage();
14-
}
10+
$cdata->before("string");
11+
$cdata->after("string");
12+
$cdata->replaceWith("string");
13+
14+
$dom = new DOMDocument();
15+
$dom->adoptNode($cdata);
16+
var_dump($dom->saveXML($cdata));
17+
1518
?>
1619
--EXPECT--
17-
Hierarchy Request Error
20+
string(0) ""
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
DOMElement: DOMChildNode, DOMParentNode modifications without a document
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
8+
$element = new DOMElement("p", " Hello World! ");
9+
$element->append("APPENDED");
10+
$element->prepend("PREPENDED");
11+
$element->after("AFTER");
12+
$element->before("BEFORE");
13+
$element->replaceWith("REPLACE");
14+
15+
$doc = new DOMDocument();
16+
$doc->adoptNode($element);
17+
echo $doc->saveXML($element), "\n";
18+
19+
?>
20+
--EXPECT--
21+
<p>PREPENDED Hello World! APPENDED</p>

0 commit comments

Comments
 (0)