Skip to content

Commit 85217a0

Browse files
committed
Mark DOMXPath as uncloneable
This never resulted in a working XPath object anyway, as trying to query or evaluate anything resulted in an "Invalid XPath context" error. Supporting this is more trouble than it's worth, so just block the clone operation.
1 parent 9c2c0c3 commit 85217a0

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

UPGRADING

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ PHP 8.4 UPGRADE NOTES
4141
DOMException now. This situation is extremely unlikely though and probably
4242
will not affect you. As a result DOMImplementation::createDocument() now has
4343
a tentative return type of DOMDocument instead of DOMDocument|false.
44+
. Previously, DOMXPath objects could be cloned, but resulted in an unusable
45+
object. This is no longer possible, and cloning a DOMXPath object now throws
46+
an error.
4447

4548
- MBString:
4649
. mb_encode_numericentity() and mb_decode_numericentity() now check that

ext/dom/php_dom.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,7 @@ PHP_MINIT_FUNCTION(dom)
872872
dom_xpath_object_handlers.offset = XtOffsetOf(dom_xpath_object, dom) + XtOffsetOf(dom_object, std);
873873
dom_xpath_object_handlers.free_obj = dom_xpath_objects_free_storage;
874874
dom_xpath_object_handlers.get_gc = dom_xpath_get_gc;
875+
dom_xpath_object_handlers.clone_obj = NULL;
875876

876877
dom_xpath_class_entry = register_class_DOMXPath();
877878
dom_xpath_class_entry->create_object = dom_xpath_objects_new;

ext/dom/tests/DOMXPath_clone.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
DOMXPath: Cloning a DOMXPath object
3+
--EXTENSIONS--
4+
dom
5+
--SKIPIF--
6+
<?php
7+
if (!class_exists('DOMXPath')) die('skip no xpath support');
8+
?>
9+
--FILE--
10+
<?php
11+
12+
$dom = new DOMDocument;
13+
$xpath = new DOMXPath($dom);
14+
try {
15+
clone $xpath;
16+
} catch (Error $e) {
17+
echo $e->getMessage(), "\n";
18+
}
19+
20+
?>
21+
--EXPECT--
22+
Trying to clone an uncloneable object of class DOMXPath

0 commit comments

Comments
 (0)