1
0
mirror of https://github.com/php/php-src.git synced 2026-04-27 01:48:26 +02:00
Files
Niels Dossche 003ebdd039 Fix GH-9628: Implicitly removing nodes from \DOMDocument breaks existing references
Change the way lifetime works in ext/libxml and ext/dom

Previously, a node could be freed even when holding a userland reference
to it. This resulted in exceptions when trying to access that node after
it has been implicitly or explicitly removed. After this patch, a node
will only be freed when the last userland reference disappears.

Fixes GH-9628.
Closes GH-11576.
2023-07-03 21:31:57 +02:00

24 lines
523 B
PHP

--TEST--
Delayed freeing processing instruction
--EXTENSIONS--
dom
--FILE--
<?php
$doc = new DOMDocument;
$pi = $doc->appendChild($doc->createElementNS('some:ns', 'container'))
->appendChild($doc->createProcessingInstruction('hello', 'world'));
echo $doc->saveXML(), "\n";
$pi->parentNode->remove();
echo $doc->saveXML(), "\n";
var_dump($pi->parentNode);
var_dump($pi->nodeValue);
?>
--EXPECT--
<?xml version="1.0"?>
<container xmlns="some:ns"><?hello world?></container>
<?xml version="1.0"?>
NULL
string(5) "world"