1--TEST--
2DOMXPath: Calling __construct() again when functions were already registered
3--EXTENSIONS--
4dom
5--SKIPIF--
6<?php
7if (!class_exists('DOMXPath')) die('skip no xpath support');
8?>
9--FILE--
10<?php
11
12$dom = new DOMDocument;
13$dom->loadXML('<root/>');
14
15class Test {
16    public function __destruct() {
17        echo "destruct\n";
18    }
19
20    public function test() {
21        echo "test\n";
22    }
23}
24
25echo "=== First run ===\n";
26
27$xpath = new DOMXPath($dom);
28$xpath->registerNamespace('foo', 'urn:foo');
29$xpath->registerPhpFunctionNS('urn:foo', 'test', [new Test, 'test']);
30
31echo "=== Reconstruct ===\n";
32
33$xpath->__construct($dom, true);
34
35echo "=== Second run ===\n";
36
37$xpath->registerNamespace('foo', 'urn:foo');
38// Note: since libxml2 commit aca16fb3d45e0b2c45364ffc1cea8eb4abaca87d this only outputs 1 warning. This seems intentional.
39// Easiest workaround is silencing the warnings
40@$xpath->query('//*[foo:test()]');
41$xpath->registerPhpFunctionNS('urn:foo', 'test', [new Test, 'test']);
42$xpath->query('//*[foo:test()]');
43
44?>
45--EXPECT--
46=== First run ===
47=== Reconstruct ===
48destruct
49=== Second run ===
50test
51destruct
52