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